List of usage examples for java.awt GridBagLayout GridBagLayout
public GridBagLayout()
From source file:Main.java
Main() {
contentPane.setLayout(new GridBagLayout());
setContentPane(contentPane);
add(myComponent);
}
From source file:Main.java
private JPanel createPanel() { JPanel p = new JPanel(); p.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0;/*from w ww. jav a2 s . c o m*/ c.gridy = 0; c.anchor = GridBagConstraints.BASELINE_LEADING; p.add(new JLabel("Loan amount"), c); c.gridx++; p.add(new JTextField(15), c); c.gridx++; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0; p.add(new JLabel("AUD"), c); c.gridx = 0; c.gridy++; c.fill = GridBagConstraints.NONE; c.weightx = 0.0; p.add(new JLabel("Loan term"), c); c.gridx++; p.add(new JTextField(15), c); c.gridx++; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0; p.add(new JLabel("Years"), c); return p; }
From source file:Main.java
public Main() { panel.setLayout(new GridBagLayout()); panel.add(subscribe);/* w w w . j av a2s .co m*/ panel.add(unsubscribe); panel.add(refresh); panel.add(save); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public void buildGUI() { JFrame.setDefaultLookAndFeelDecorated(true); JFrame f = new JFrame(); f.setResizable(false);//from w w w. j a v a 2 s . c o m removeMinMaxClose(f); JPanel p = new JPanel(new GridBagLayout()); JButton btn = new JButton("Exit"); p.add(btn, new GridBagConstraints()); f.getContentPane().add(p); f.setSize(400, 300); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); btn.addActionListener(e -> System.exit(0)); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new BorderLayout()); JPanel upper = new JPanel(); GridBagLayout gridbag = new GridBagLayout(); upper.setLayout(gridbag);/* w w w.ja v a2 s. co m*/ GridBagConstraints gbc = new GridBagConstraints(); JButton toolbar1 = new JButton("toolbar1"); JButton toolbar2 = new JButton("toolbar2"); JButton toolbar3 = new JButton("toolbar3"); gbc.gridx = 0; gbc.gridy = 0; gbc.weightx = 1.0; gbc.weighty = 1.0; gbc.anchor = GridBagConstraints.WEST; upper.add(toolbar1, gbc); gbc.gridx = 1; gbc.anchor = GridBagConstraints.CENTER; upper.add(toolbar2, gbc); gbc.gridx = 2; gbc.anchor = GridBagConstraints.EAST; gbc.gridwidth = GridBagConstraints.REMAINDER; upper.add(toolbar3, gbc); add(upper, BorderLayout.NORTH); JPanel something = new JPanel(); something.setBackground(Color.WHITE); something.setPreferredSize(new Dimension(600, 600)); something.repaint(); add(something, BorderLayout.CENTER); pack(); setVisible(true); }
From source file:Main.java
public Main() { setPreferredSize(new Dimension(500, 500)); getContentPane().setLayout(new BorderLayout()); JPanel panel = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(4, 4, 4, 4); panel.add(new JLabel("Label"), c); panel.add(new JTextField(20), c); c.gridwidth = GridBagConstraints.REMAINDER; panel.add(new JButton("btn"), c); c.gridwidth = 1;// ww w . j a v a2 s . c om panel.add(new JLabel("Name"), c); panel.add(new JTextField(20), c); c.gridwidth = GridBagConstraints.REMAINDER; panel.add(new JButton("btn"), c); c.weighty = 1.0; panel.add(Box.createGlue(), c); add(panel, BorderLayout.LINE_START); pack(); setVisible(true); }
From source file:ColorChooserDemo.java
protected void createUI() { setSize(400, 400);/* ww w.j a v a 2 s .c o m*/ getContentPane().setLayout(new GridBagLayout()); JButton colorButton = new JButton("Choose a color..."); getContentPane().add(colorButton); colorButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { Color c = JColorChooser.showDialog(ColorChooserDemo.this, "Choose a color...", getBackground()); if (c != null) getContentPane().setBackground(c); } }); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { System.exit(0); } }); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); contentPane = new JPanel(); setContentPane(contentPane);/*from w w w . j a v a 2 s .c o m*/ GridBagLayout gbl_panel = new GridBagLayout(); gbl_panel.columnWidths = new int[] { 0, 0, 0, 0 }; gbl_panel.rowHeights = new int[] { 0, 0, 0, 0, 0, 0 }; gbl_panel.columnWeights = new double[] { 0.0, 0.1, 0.0, Double.MIN_VALUE }; gbl_panel.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE }; contentPane.setLayout(gbl_panel); JButton btn_1 = new JButton("B1"); GridBagConstraints gbc_comboBox = new GridBagConstraints(); gbc_comboBox.insets = new Insets(0, 0, 5, 20); gbc_comboBox.gridx = 2; gbc_comboBox.gridy = 0; gbc_comboBox.weightx = 0.0; contentPane.add(btn_1, gbc_comboBox); JButton btn_2 = new JButton("B2"); GridBagConstraints gbc_btnNewButton = new GridBagConstraints(); gbc_btnNewButton.insets = new Insets(0, 0, 5, 20); gbc_btnNewButton.gridx = 2; gbc_btnNewButton.gridy = 1; contentPane.add(btn_2, gbc_btnNewButton); setSize(200, 300); }
From source file:Main.java
public MyContentPane() { setLayout(new GridBagLayout()); add(new JPanelOfInterest()); }
From source file:Main.java
public TestPane() { setLayout(new GridBagLayout()); update = new JButton("Update"); comboBox = new JComboBox(); update.addActionListener(e -> updateCombo()); updateCombo();//from www . java 2 s . c o m add(comboBox); add(update); }