Example usage for java.awt GridLayout GridLayout

List of usage examples for java.awt GridLayout GridLayout

Introduction

In this page you can find the example usage for java.awt GridLayout GridLayout.

Prototype

public GridLayout(int rows, int cols) 

Source Link

Document

Creates a grid layout with the specified number of rows and columns.

Usage

From source file:SampleSortingTableModel.java

public SortableTableModelAbstractTableModel() {
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    JTable tableOrig = new JTable(model);
    tableOrig.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    JTable tableSorted = new JTable(new SampleSortingTableModel(model, 0));
    tableSorted.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    JPanel panel = new JPanel(new GridLayout(1, 2));
    panel.add(new JScrollPane(tableOrig));
    panel.add(new JScrollPane(tableSorted));
    getContentPane().add(panel, BorderLayout.CENTER);
    pack();//from  w  w  w. j a  v a2  s .  c  om
}

From source file:LabelDnD2.java

public LabelDnD2() {
    super(new BorderLayout());

    JColorChooser chooser = new JColorChooser();
    chooser.setDragEnabled(true);//from w  w  w  .ja v a 2 s. co  m

    label = new JLabel("I'm a Label and I accept color!", SwingConstants.LEADING);
    label.setTransferHandler(new TransferHandler("foreground"));

    MouseListener listener = new DragMouseAdapter();
    label.addMouseListener(listener);
    JPanel lpanel = new JPanel(new GridLayout(1, 1));
    TitledBorder t2 = BorderFactory.createTitledBorder("JLabel: drop color onto the label");
    lpanel.add(label);
    lpanel.setBorder(t2);

    add(chooser, BorderLayout.CENTER);
    add(lpanel, BorderLayout.PAGE_END);
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
}

From source file:gtu._work.ui.EstoreDAOCodeGenerateUI.java

private void initGUI() {
    try {/* ww  w .  ja v  a 2 s .c om*/
        BorderLayout thisLayout = new BorderLayout();
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(thisLayout);
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            jTabbedPane1.setPreferredSize(new java.awt.Dimension(717, 582));
            {
                jPanel1 = new JPanel();
                GridLayout jPanel1Layout = new GridLayout(15, 1);
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("", null, jPanel1, null);
                {
                    jLabel1 = new JLabel();
                    jPanel1.add(jLabel1);
                    jLabel1.setText("entity\u540d\u7a31");
                }
                {
                    entityNameText = new JTextField();
                    jPanel1.add(entityNameText);
                }
                {
                    jLabel4 = new JLabel();
                    jPanel1.add(jLabel4);
                    jLabel4.setText("DAOImpl\u540d\u7a31");
                }
                {
                    daoImplText = new JTextField();
                    jPanel1.add(daoImplText);
                }
                {
                    jLabel5 = new JLabel();
                    jPanel1.add(jLabel5);
                    jLabel5.setText("DAOInterface\u540d\u7a31");
                }
                {
                    daoInterfaceText = new JTextField();
                    jPanel1.add(daoInterfaceText);
                }
                {
                    updateBtn = new JButton();
                    jPanel1.add(updateBtn);
                    updateBtn.setText("\u66f4\u65b0");
                    updateBtn.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            updateBtnActionPerformed(evt);
                        }
                    });
                }
                {
                    makeFileBtn = new JButton();
                    jPanel1.add(makeFileBtn);
                    makeFileBtn.setText("\u7522\u751f\u6a94\u6848");
                    makeFileBtn.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            try {
                                makeFileBtnActionPerformed(evt);
                            } catch (IOException e) {
                                JCommonUtil.handleException(e);
                            }
                        }
                    });
                }
            }
            {
                jPanel2 = new JPanel();
                BorderLayout jPanel2Layout = new BorderLayout();
                jPanel2.setLayout(jPanel2Layout);
                jTabbedPane1.addTab("xml", null, jPanel2, null);
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel2.add(jScrollPane1, BorderLayout.CENTER);
                    jScrollPane1.setPreferredSize(new java.awt.Dimension(712, 458));
                    {
                        jScrollPane2 = new JScrollPane();
                        jScrollPane1.setViewportView(jScrollPane2);
                        {
                            xmlConfigArea = new JTextArea();
                            jScrollPane2.setViewportView(xmlConfigArea);
                        }
                    }
                }
            }
        }
        pack();
        this.setSize(733, 525);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:es.emergya.ui.base.plugins.PluginContainer.java

/**
 * Default constructor.
 */
public PluginContainer() {
    this.setLayout(new GridLayout(1, 1));
}

From source file:ExtendedDnDDemo.java

public ExtendedDnDDemo() {
    super(new GridLayout(3, 1));
    add(createArea());
    add(createList());
    add(createTable());
}

From source file:components.LayeredPaneDemo2.java

public LayeredPaneDemo2() {
    setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));

    //Create and load the duke icon.
    final ImageIcon icon = createImageIcon("images/dukeWaveRed.gif");

    //Create and set up the layered pane.
    layeredPane = new JLayeredPane();
    layeredPane.setPreferredSize(new Dimension(300, 310));
    layeredPane.setBorder(BorderFactory.createTitledBorder("Move the Mouse to Move Duke"));
    layeredPane.addMouseMotionListener(this);

    //Add several labels to the layered pane.
    layeredPane.setLayout(new GridLayout(2, 3));
    for (int i = 0; i < layerStrings.length; i++) {
        JLabel label = createColoredLabel(layerStrings[i], layerColors[i]);
        layeredPane.add(label, new Integer(i));
    }/*from  w  ww .  j av  a  2 s  .  c  o m*/

    //Create and add the Duke label to the layered pane.
    dukeLabel = new JLabel(icon);
    if (icon == null) {
        System.err.println("Duke icon not found; using black rectangle instead.");
        dukeLabel.setOpaque(true);
        dukeLabel.setBackground(Color.BLACK);
    }
    layeredPane.add(dukeLabel, new Integer(2), 0);

    //Add control pane and layered pane to this JPanel.
    add(Box.createRigidArea(new Dimension(0, 10)));
    add(createControlPanel());
    add(Box.createRigidArea(new Dimension(0, 10)));
    add(layeredPane);
}

From source file:components.TreeDemo.java

public TreeDemo() {
    super(new GridLayout(1, 0));

    //Create the nodes.
    DefaultMutableTreeNode top = new DefaultMutableTreeNode("The Java Series");
    createNodes(top);//from   w  ww.ja  va  2s.co  m

    //Create a tree that allows one selection at a time.
    tree = new JTree(top);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    //Listen for when the selection changes.
    tree.addTreeSelectionListener(this);

    if (playWithLineStyle) {
        System.out.println("line style = " + lineStyle);
        tree.putClientProperty("JTree.lineStyle", lineStyle);
    }

    //Create the scroll pane and add the tree to it. 
    JScrollPane treeView = new JScrollPane(tree);

    //Create the HTML viewing pane.
    htmlPane = new JEditorPane();
    htmlPane.setEditable(false);
    initHelp();
    JScrollPane htmlView = new JScrollPane(htmlPane);

    //Add the scroll panes to a split pane.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setTopComponent(treeView);
    splitPane.setBottomComponent(htmlView);

    Dimension minimumSize = new Dimension(100, 50);
    htmlView.setMinimumSize(minimumSize);
    treeView.setMinimumSize(minimumSize);
    splitPane.setDividerLocation(100);
    splitPane.setPreferredSize(new Dimension(500, 300));

    //Add the split pane to this panel.
    add(splitPane);
}

From source file:misc.FocusTraversalDemo.java

public FocusTraversalDemo() {
    super(new BorderLayout());

    JTextField tf1 = new JTextField("Field 1");
    JTextField tf2 = new JTextField("A Bigger Field 2");
    JTextField tf3 = new JTextField("Field 3");
    JTextField tf4 = new JTextField("A Bigger Field 4");
    JTextField tf5 = new JTextField("Field 5");
    JTextField tf6 = new JTextField("A Bigger Field 6");
    JTable table = new JTable(4, 3);
    togglePolicy = new JCheckBox("Custom FocusTraversalPolicy");
    togglePolicy.setActionCommand("toggle");
    togglePolicy.addActionListener(this);
    togglePolicy.setFocusable(false); //Remove it from the focus cycle.
    //Note that HTML is allowed and will break this run of text
    //across two lines.
    label = new JLabel(
            "<html>Use Tab (or Shift-Tab) to navigate from component to component.<p>Control-Tab (or Control-Shift-Tab) allows you to break out of the JTable.</html>");

    JPanel leftTextPanel = new JPanel(new GridLayout(3, 2));
    leftTextPanel.add(tf1, BorderLayout.PAGE_START);
    leftTextPanel.add(tf3, BorderLayout.CENTER);
    leftTextPanel.add(tf5, BorderLayout.PAGE_END);
    leftTextPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 5));
    JPanel rightTextPanel = new JPanel(new GridLayout(3, 2));
    rightTextPanel.add(tf2, BorderLayout.PAGE_START);
    rightTextPanel.add(tf4, BorderLayout.CENTER);
    rightTextPanel.add(tf6, BorderLayout.PAGE_END);
    rightTextPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 5));
    JPanel tablePanel = new JPanel(new GridLayout(0, 1));
    tablePanel.add(table, BorderLayout.CENTER);
    tablePanel.setBorder(BorderFactory.createEtchedBorder());
    JPanel bottomPanel = new JPanel(new GridLayout(2, 1));
    bottomPanel.add(togglePolicy, BorderLayout.PAGE_START);
    bottomPanel.add(label, BorderLayout.PAGE_END);

    add(leftTextPanel, BorderLayout.LINE_START);
    add(rightTextPanel, BorderLayout.CENTER);
    add(tablePanel, BorderLayout.LINE_END);
    add(bottomPanel, BorderLayout.PAGE_END);
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
    Vector<Component> order = new Vector<Component>(7);
    order.add(tf1);//  ww  w .j a  v a 2 s  .  c om
    order.add(tf2);
    order.add(tf3);
    order.add(tf4);
    order.add(tf5);
    order.add(tf6);
    order.add(table);
    newPolicy = new MyOwnFocusTraversalPolicy(order);
}

From source file:components.DynamicTreeDemo.java

public DynamicTreeDemo() {
    super(new BorderLayout());

    //Create the components.
    treePanel = new DynamicTree();
    populateTree(treePanel);/*from ww  w.j a v  a2 s  .c o  m*/

    JButton addButton = new JButton("Add");
    addButton.setActionCommand(ADD_COMMAND);
    addButton.addActionListener(this);

    JButton removeButton = new JButton("Remove");
    removeButton.setActionCommand(REMOVE_COMMAND);
    removeButton.addActionListener(this);

    JButton clearButton = new JButton("Clear");
    clearButton.setActionCommand(CLEAR_COMMAND);
    clearButton.addActionListener(this);

    //Lay everything out.
    treePanel.setPreferredSize(new Dimension(300, 150));
    add(treePanel, BorderLayout.CENTER);

    JPanel panel = new JPanel(new GridLayout(0, 3));
    panel.add(addButton);
    panel.add(removeButton);
    panel.add(clearButton);
    add(panel, BorderLayout.SOUTH);
}

From source file:events.ContainerEventDemo.java

public ContainerEventDemo() {
    super(new GridBagLayout());
    GridBagLayout gridbag = (GridBagLayout) getLayout();
    GridBagConstraints c = new GridBagConstraints();

    //Initialize an empty list of buttons.
    buttonList = new Vector<JButton>(10, 10);

    //Create all the components.
    addButton = new JButton("Add a button");
    addButton.setActionCommand(ADD);//from   ww  w. j a  va2  s .c  om
    addButton.addActionListener(this);

    removeButton = new JButton("Remove a button");
    removeButton.setActionCommand(REMOVE);
    removeButton.addActionListener(this);

    buttonPanel = new JPanel(new GridLayout(1, 1));
    buttonPanel.setPreferredSize(new Dimension(200, 75));
    buttonPanel.addContainerListener(this);

    display = new JTextArea();
    display.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(display);
    scrollPane.setPreferredSize(new Dimension(200, 75));

    clearButton = new JButton("Clear text area");
    clearButton.setActionCommand(CLEAR);
    clearButton.addActionListener(this);

    c.fill = GridBagConstraints.BOTH; //Fill entire cell.
    c.weighty = 1.0; //Button area and message area have equal height.
    c.gridwidth = GridBagConstraints.REMAINDER; //end of row
    gridbag.setConstraints(scrollPane, c);
    add(scrollPane);

    c.weighty = 0.0;
    gridbag.setConstraints(clearButton, c);
    add(clearButton);

    c.weightx = 1.0; //Add/remove buttons have equal width.
    c.gridwidth = 1; //NOT end of row
    gridbag.setConstraints(addButton, c);
    add(addButton);

    c.gridwidth = GridBagConstraints.REMAINDER; //end of row
    gridbag.setConstraints(removeButton, c);
    add(removeButton);

    c.weighty = 1.0; //Button area and message area have equal height.
    gridbag.setConstraints(buttonPanel, c);
    add(buttonPanel);

    setPreferredSize(new Dimension(400, 400));
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
}