Results 1 to 1 of 1
- 02-21-2011, 04:15 PM #1Member
- Join Date
- Apr 2010
- Rep Power
Position 5 buttons with GridBagConstraints in Swing
How to position 5 buttons with GridBagConstraints in Swing so that the first button (B1) are at the first column, the next four buttons (B2, B3, B4, B5) are grouped together with some space ( ) between the first button and next four buttons, and the fifth button (B5) is placed at the end of the row of the screen?
The following code does not work - there is space between each button.
The posted source is a simplication of my real source code, which is more complex, so I use GridBagLayout.
JButton button = new JButton("Note"); c.fill = GridBagConstraints.LAST_LINE_START; c.gridx = 0; c.gridwidth = 1; c.gridy = 5; pane.add(button, c); button = new JButton("Remove"); c.gridx = 5; pane.add(button, c); button = new JButton("Add"); c.gridx = 6; pane.add(button, c); button = new JButton("Add Component"); c.gridwidth = GridBagConstraints.RELATIVE; c.gridx = 7; pane.add(button, c); button = new JButton("Read"); c.gridwidth = GridBagConstraints.REMAINDER; c.gridx = 8; pane.add(button, c);
Last edited by albertkao; 02-21-2011 at 07:19 PM.
- By noobgrammer in forum New To JavaReplies: 5Last Post: 07-03-2010, 04:12 AM
- By adi in forum AWT / SwingReplies: 3Last Post: 12-28-2008, 06:04 PM
- By email@example.com in forum AWT / SwingReplies: 2Last Post: 09-15-2008, 09:50 AM
- By Aswq in forum New To JavaReplies: 2Last Post: 07-21-2008, 09:08 PM
- By Java Tip in forum javax.swingReplies: 0Last Post: 06-26-2008, 07:37 PM