List of usage examples for java.awt GridBagConstraints HORIZONTAL
int HORIZONTAL
To view the source code for java.awt GridBagConstraints HORIZONTAL.
Click Source Link
From source file:Main.java
/** * Creates a panel that contains all of the components on top of each other in north, * and tries to make them as small as possible (probably by using getPreferredSize()). * * @deprecated use proper layout, usually no need to use such complex/ugly layouting *///from www. j ava 2 s . c o m public static JPanel combineInNorth(JComponent[] components) { JPanel result = new JPanel(); if (components.length == 0) { return result; } result.setLayout(new BorderLayout()); JPanel contentPanel = new JPanel(); result.add(contentPanel, BorderLayout.NORTH); contentPanel.setLayout(new GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); constraints.gridx = 0; constraints.weightx = 1.0; constraints.fill = GridBagConstraints.HORIZONTAL; for (int i = 0; i < components.length; i++) { contentPanel.add(components[i], constraints); } if (result.isVisible()) result.doLayout(); return result; }
From source file:Main.java
Main() { this.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0;/*from ww w . ja v a2 s . c om*/ this.add(new Button("Resizable"), c); c = new GridBagConstraints(); c.weightx = 0.0; this.add(new Button("Not Resizable")); this.pack(); }
From source file:Main.java
Main() { setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(500, 500);// w ww . j a v a2 s .c om JPanel panel1 = new JPanel(new GridBagLayout()); JButton b1 = new JButton("button 1"), b2 = new JButton("button 2"); panel1.add(b1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); panel1.add(b2, new GridBagConstraints(1, 0, 1, 1, 2.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); add(panel1); setVisible(true); }
From source file:Main.java
public Main() { JPanel bigPanel = new JPanel(new GridBagLayout()); JPanel panel_a = new JPanel(); JButton btnA = new JButton("button a"); panel_a.add(btnA);//from w w w. j a v a 2 s. c om JPanel panel_b = new JPanel(); JButton btnB = new JButton("button b"); panel_b.add(btnB); GridBagConstraints c = new GridBagConstraints(); c.gridwidth = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0; bigPanel.add(panel_a, c); bigPanel.add(panel_b, c); c.weighty = 1.0; bigPanel.add(new JPanel(), c); this.add(bigPanel); }
From source file:Main.java
public static JPanel createKV(final Component key, final Component value, final int keyWidth, final boolean fill) { initComponentHeight(key, value);/*from w w w . j a v a2 s. c o m*/ if (keyWidth > 0) { key.setPreferredSize(new Dimension(keyWidth, key.getPreferredSize().height)); } final JPanel jp = new JPanel(new GridBagLayout()); final GridBagConstraints gbc = new GridBagConstraints(); gbc.anchor = GridBagConstraints.WEST; gbc.gridx = 0; gbc.gridy = 0; gbc.insets = new Insets(0, 0, 0, 4); jp.add(key, gbc); gbc.gridx = 1; gbc.insets = new Insets(0, 0, 0, 0); gbc.weightx = 1.0; if (fill) { gbc.fill = GridBagConstraints.HORIZONTAL; } jp.add(value, gbc); return jp; }
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 w w.j a v a2s . 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() { GridBagLayout layout = new GridBagLayout(); GridBagConstraints constraints = new GridBagConstraints(); getContentPane().setLayout(layout);/*from ww w .j ava 2s .co m*/ constraints.anchor = GridBagConstraints.WEST; JLabel l1 = new JLabel("First Name:"); constraints.gridx = 0; constraints.gridy = 0; constraints.gridwidth = 1; constraints.gridheight = 1; constraints.weightx = 0; constraints.weighty = 0; constraints.fill = GridBagConstraints.BOTH; constraints.insets = new Insets(5, 5, 5, 5); layout.setConstraints(l1, constraints); getContentPane().add(l1); JTextField t1 = new JTextField(); constraints.gridx = 1; constraints.gridy = 0; constraints.weightx = 1; constraints.fill = GridBagConstraints.HORIZONTAL; constraints.insets = new Insets(5, 5, 5, 5); layout.setConstraints(t1, constraints); getContentPane().add(t1); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(700, 500); }
From source file:layout.GridBagLayoutDemo.java
public static void addComponentsToPane(Container pane) { if (RIGHT_TO_LEFT) { pane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); }/*from w ww . jav a 2s . c o m*/ JButton button; pane.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); if (shouldFill) { //natural height, maximum width c.fill = GridBagConstraints.HORIZONTAL; } button = new JButton("Button 1"); if (shouldWeightX) { c.weightx = 0.5; } c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.gridy = 0; pane.add(button, c); button = new JButton("Button 2"); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0.5; c.gridx = 1; c.gridy = 0; pane.add(button, c); button = new JButton("Button 3"); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0.5; c.gridx = 2; c.gridy = 0; pane.add(button, c); button = new JButton("Long-Named Button 4"); c.fill = GridBagConstraints.HORIZONTAL; c.ipady = 40; //make this component tall c.weightx = 0.0; c.gridwidth = 3; c.gridx = 0; c.gridy = 1; pane.add(button, c); button = new JButton("5"); c.fill = GridBagConstraints.HORIZONTAL; c.ipady = 0; //reset to default c.weighty = 1.0; //request any extra vertical space c.anchor = GridBagConstraints.PAGE_END; //bottom of space c.insets = new Insets(10, 0, 0, 0); //top padding c.gridx = 1; //aligned with button 2 c.gridwidth = 2; //2 columns wide c.gridy = 2; //third row pane.add(button, c); }
From source file:GridBagLayoutDemo.java
public static void addComponentsToPane(Container pane) { if (RIGHT_TO_LEFT) { pane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); }//from w w w. ja va2 s . co m JButton button; pane.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); if (shouldFill) { // natural height, maximum width c.fill = GridBagConstraints.HORIZONTAL; } button = new JButton("Button 1"); if (shouldWeightX) { c.weightx = 0.5; } c.gridx = 0; c.gridy = 0; pane.add(button, c); button = new JButton("Button 2"); c.gridx = 1; c.gridy = 0; pane.add(button, c); button = new JButton("Button 3"); c.gridx = 2; c.gridy = 0; pane.add(button, c); button = new JButton("Long-Named Button 4"); c.ipady = 40; // make this component tall c.weightx = 0.0; c.gridwidth = 3; c.gridx = 0; c.gridy = 1; pane.add(button, c); button = new JButton("5"); c.ipady = 0; // reset to default c.weighty = 1.0; // request any extra vertical space c.anchor = GridBagConstraints.PAGE_END; // bottom of space c.insets = new Insets(10, 0, 0, 0); // top padding c.gridx = 1; // aligned with button 2 c.gridwidth = 2; // 2 columns wide c.gridy = 2; // third row pane.add(button, c); }
From source file:Main.java
public LoginPanel() { setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.anchor = GridBagConstraints.CENTER; gbc.weightx = 1;//w ww .ja va 2s . com gbc.gridx = 2; gbc.anchor = GridBagConstraints.EAST; JLabel label = new JLabel("Username: "); add(label, gbc); gbc.anchor = GridBagConstraints.WEST; gbc.gridx = 3; gbc.gridwidth = 2; add(userfield, gbc); gbc.gridy = 1; add(passfield, gbc); gbc.anchor = GridBagConstraints.EAST; gbc.gridx = 2; label = new JLabel("Password: "); add(label, gbc); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridy = 2; gbc.gridx = 1; gbc.gridwidth = 5; add(new JSeparator(JSeparator.HORIZONTAL), gbc); }