List of usage examples for java.awt GridBagConstraints GridBagConstraints
public GridBagConstraints()
From source file:Main.java
public static void main(String[] argv) throws Exception { JFrame frame = new JFrame(); Container container = frame.getContentPane(); GridBagLayout gbl = new GridBagLayout(); container.setLayout(gbl);// www. j av a 2 s . c om GridBagConstraints gbc = new GridBagConstraints(); JButton component1 = new JButton("a"); JButton component2 = new JButton("b"); gbc.gridx = 1; gbc.gridy = 1; gbl.setConstraints(component1, gbc); container.add(component1); gbc.gridx = 0; gbc.gridy = 0; gbl.setConstraints(component2, gbc); container.add(component2); container.add(component1); container.add(component2); frame.pack(); frame.setVisible(true); gbl.layoutContainer(container); int[][] dim = gbl.getLayoutDimensions(); int cols = dim[0].length; int rows = dim[1].length; System.out.println(cols); System.out.println(rows); }
From source file:GridBagLayoutGridHeight.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container pane = f.getContentPane(); pane.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); pane.add(new JLabel("First row, first column"), gbc); pane.add(new JLabel("First row, second column"), gbc); gbc.gridheight = GridBagConstraints.REMAINDER; gbc.fill = GridBagConstraints.VERTICAL; pane.add(new JLabel("First row, third column"), gbc); gbc.gridx = 0;//from ww w . jav a 2s .c o m gbc.gridheight = 1; gbc.fill = GridBagConstraints.NONE; pane.add(new JButton("Second row"), gbc); pane.add(new JButton("Third row"), gbc); f.setSize(600, 300); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { final JFrame frame = new JFrame(Main.class.getSimpleName()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel btmPanel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.weighty = 1.0;/* w ww . j a va2 s . co m*/ gbc.weightx = 1.0; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = new Insets(5, 5, 5, 5); gbc.anchor = GridBagConstraints.NORTH; JButton comp = new JButton("Panel-1"); btmPanel.add(comp, gbc); JButton comp2 = new JButton("Panel-2"); btmPanel.add(comp2, gbc); JButton comp3 = new JButton("Panel-3"); comp3.setPreferredSize(new Dimension(comp.getPreferredSize().width, comp.getPreferredSize().height + 10)); btmPanel.add(comp3, gbc); frame.add(btmPanel); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JFrame frame = new JFrame(); Container container = frame.getContentPane(); GridBagLayout gbl = new GridBagLayout(); container.setLayout(gbl);//from w ww . j av a 2 s . co m // Place a component at cell location (1,1) GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 1; gbc.gridy = 1; JButton component = new JButton("a"); // Associate the gridbag constraints with the component gbl.setConstraints(component, gbc); container.add(component); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame dialog = new JFrame(); dialog.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); dialog.setResizable(true);/*w ww .j a v a2 s. co m*/ JPanel guiHolder = new JPanel(); guiHolder.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.anchor = GridBagConstraints.PAGE_START; gbc.weightx = 1.0; gbc.weighty = 1.0; guiHolder.add(new JLabel("my test"), gbc); dialog.add(guiHolder); dialog.setSize(new Dimension(320, 240)); dialog.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String title = "GridBagLayout"; JFrame frame = new JFrame(title); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); for (int y = 0; y < 3; y++) { for (int x = 0; x < 4; x++) { gbc.gridx = x;//from w ww . ja va 2 s .c o m gbc.gridy = y; String text = "Button (" + x + ", " + y + ")"; contentPane.add(new JButton(text), gbc); } } frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JFrame frame = new JFrame(); GridBagLayout gbl = new GridBagLayout(); frame.setLayout(gbl);/*from ww w . j ava 2 s .co m*/ JButton component = new JButton("1"); frame.add(component); frame.add(new JButton("2")); gbl.layoutContainer(frame); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.NONE; gbl.setConstraints(component, gbc); frame.add(component); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JFrame frame = new JFrame(); GridBagLayout gbl = new GridBagLayout(); frame.setLayout(gbl);/*from w w w .j a v a2s.c om*/ JButton component = new JButton("1"); frame.add(component); frame.add(new JButton("2")); gbl.layoutContainer(frame); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 1; gbc.weightx = 1; gbc.weighty = 2; gbl.setConstraints(component, gbc); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JFrame frame = new JFrame(); GridBagLayout gbl = new GridBagLayout(); frame.setLayout(gbl);/*from w w w . j a v a 2s. c om*/ JButton component = new JButton("1"); frame.add(component); frame.add(new JButton("2")); gbl.layoutContainer(frame); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.VERTICAL; gbl.setConstraints(component, gbc); frame.add(component); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JFrame frame = new JFrame(); GridBagLayout gbl = new GridBagLayout(); frame.setLayout(gbl);/*w w w . j a v a 2 s .co m*/ JButton component = new JButton("1"); frame.add(component); frame.add(new JButton("2")); gbl.layoutContainer(frame); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.BOTH; gbl.setConstraints(component, gbc); frame.add(component); frame.pack(); frame.setVisible(true); }