List of usage examples for java.awt GridBagConstraints GridBagConstraints
public GridBagConstraints()
From source file:Main.java
public static void main(String[] args) { JLabel userLabel = new JLabel("User Name"); JLabel passLabel = new JLabel("Password"); JTextField userText = new JTextField(20); JPasswordField passText = new JPasswordField(20); JButton loginButton = new JButton("Login"); JPanel panel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(4, 4, 4, 4); gbc.gridx = 0;//from w w w . j a v a2s.c o m gbc.gridy = 0; gbc.fill = GridBagConstraints.NONE; panel.add(userLabel, gbc); gbc.gridx = 1; gbc.gridy = 0; gbc.fill = GridBagConstraints.HORIZONTAL; panel.add(userText, gbc); gbc.gridx = 0; gbc.gridy = 1; gbc.fill = GridBagConstraints.NONE; panel.add(passLabel, gbc); gbc.gridx = 1; gbc.gridy = 1; gbc.fill = GridBagConstraints.HORIZONTAL; panel.add(passText, gbc); gbc.gridx = 0; gbc.gridy = 2; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.CENTER; gbc.gridwidth = 2; panel.add(loginButton, gbc); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new JScrollPane(panel)); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); final JLabel valueLabel = new JLabel(String.valueOf(value)); JButton decButton = new JButton("-"); decButton.addActionListener(e -> valueLabel.setText(String.valueOf(--value))); JButton incButton = new JButton("+"); incButton.addActionListener(e -> valueLabel.setText(String.valueOf(++value))); JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.weightx = 1;//ww w . j a v a 2s. c o m c.gridx = 0; c.gridy = 0; panel.add(decButton, c); c.gridx = 1; panel.add(valueLabel, c); c.gridx = 2; panel.add(incButton, c); c.gridy = 1; int w = 32; for (c.gridx = 0; c.gridx < 3; c.gridx++) { panel.add(Box.createHorizontalStrut(w), c); } frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.add(panel); 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);// ww w .j a v a 2 s . c o m JButton component = new JButton("1"); frame.add(new JButton("2")); frame.add(new JButton("3")); frame.add(new JButton("4")); frame.add(new JButton("5")); frame.add(component); frame.add(new JButton("6")); frame.add(new JButton("7")); frame.add(new JButton("8")); frame.add(new JButton("9")); frame.add(new JButton("0")); gbl.layoutContainer(frame); GridBagConstraints gbc = new GridBagConstraints(); int top = 20; int left = 20; int bottom = 2; int right = 40; gbc.insets = new Insets(top, left, bottom, right); gbl.setConstraints(component, gbc); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame(); frame.setResizable(false);/*from w ww . j a v a2s.co m*/ removeButtons(frame); JPanel panel = new JPanel(new GridBagLayout()); JButton button = new JButton("Exit"); panel.add(button, new GridBagConstraints()); frame.getContentPane().add(panel); frame.setSize(400, 300); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); button.addActionListener(e -> System.exit(0)); }
From source file:SampleField.java
public static void main(String[] args) { GridBagConstraints g = new GridBagConstraints(); printFieldNames(g); }
From source file:TextAcceleratorExample.java
public static void main(String[] args) { try {/*w w w . j a va 2 s.c o m*/ UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JLabel l; JTextField t; JButton b; JFrame f = new JFrame("Text Accelerator Example"); Container cp = f.getContentPane(); cp.setLayout(new GridBagLayout()); cp.setBackground(UIManager.getColor("control")); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = GridBagConstraints.RELATIVE; c.gridwidth = 1; c.gridheight = 1; c.insets = new Insets(2, 2, 2, 2); c.anchor = GridBagConstraints.EAST; cp.add(l = new JLabel("Name:", SwingConstants.RIGHT), c); l.setDisplayedMnemonic('n'); cp.add(l = new JLabel("House/Street:", SwingConstants.RIGHT), c); l.setDisplayedMnemonic('h'); cp.add(l = new JLabel("City:", SwingConstants.RIGHT), c); l.setDisplayedMnemonic('c'); cp.add(l = new JLabel("State/County:", SwingConstants.RIGHT), c); l.setDisplayedMnemonic('s'); cp.add(l = new JLabel("Zip/Post code:", SwingConstants.RIGHT), c); l.setDisplayedMnemonic('z'); cp.add(l = new JLabel("Telephone:", SwingConstants.RIGHT), c); l.setDisplayedMnemonic('t'); cp.add(b = new JButton("Clear"), c); b.setMnemonic('l'); c.gridx = 1; c.gridy = 0; c.weightx = 1.0; c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.CENTER; cp.add(t = new JTextField(35), c); t.setFocusAccelerator('n'); c.gridx = 1; c.gridy = GridBagConstraints.RELATIVE; cp.add(t = new JTextField(35), c); t.setFocusAccelerator('h'); cp.add(t = new JTextField(35), c); t.setFocusAccelerator('c'); cp.add(t = new JTextField(35), c); t.setFocusAccelerator('s'); cp.add(t = new JTextField(35), c); t.setFocusAccelerator('z'); cp.add(t = new JTextField(35), c); t.setFocusAccelerator('t'); c.weightx = 0.0; c.fill = GridBagConstraints.NONE; cp.add(b = new JButton("OK"), c); b.setMnemonic('o'); f.pack(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setTitle("Example2"); f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); JPanel p1 = new JPanel(new FlowLayout(FlowLayout.CENTER)); p1.setBorder(new TitledBorder(new LineBorder(Color.BLACK), "JPanel 1")); for (int i = 0; i < NB1; i++) p1.add(new JButton("Button " + i)); JPanel p2 = new JPanel(new FlowLayout(FlowLayout.CENTER)); p2.setBorder(new TitledBorder(new LineBorder(Color.BLACK), "JPanel 2")); for (int i = NB1; i < NB2; i++) p2.add(new JButton("Button " + i)); JPanel p3 = new JPanel(new FlowLayout(FlowLayout.CENTER)); p3.setBorder(new TitledBorder(new LineBorder(Color.BLACK), "JPanel 3")); for (int i = NB2; i < NB3; i++) p3.add(new JButton("Button " + i)); JPanel global = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; // added gbc.weightx = 1.0f; // added gbc.gridy = 0;/*from w w w . j a va2 s. c o m*/ global.add(p1, gbc); gbc.gridy++; global.add(p2, gbc); gbc.gridy++; global.add(p3, gbc); f.add(global); f.pack(); f.setVisible(true); }
From source file:Main.java
public static GridBagConstraints getGridBagConstraints() { GridBagConstraints c = new GridBagConstraints(); return c; }
From source file:Main.java
public static GridBagConstraints defaultConstraints() { GridBagConstraints constraints = new GridBagConstraints(); constraints.anchor = GridBagConstraints.WEST; constraints.gridx = 0;/*from w ww . j av a 2 s . c o m*/ constraints.gridy = 0; constraints.ipadx = 3; constraints.ipady = 2; constraints.weightx = 1; // constraints.weighty = 1; constraints.anchor = GridBagConstraints.NORTHWEST; constraints.fill = GridBagConstraints.BOTH; return constraints; }
From source file:Main.java
public static GridBagConstraints getGridBagConstraints(int gridX, int gridY, int gridWidth, int gridHeight, int fill, int anchor) { GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = gridX;//from www .j a v a2 s. c o m gbc.gridy = gridY; gbc.gridwidth = gridWidth; gbc.gridheight = gridHeight; gbc.fill = fill; gbc.anchor = anchor; return gbc; }