Results 1 to 1 of 1
- 02-21-2011, 03:15 PM #1
Member
- Join Date
- Apr 2010
- Posts
- 9
- Rep Power
- 0
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?
i.e.
B1 B2B3B4B5
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.
Java Code: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 06:19 PM.
Similar Threads
-
GridBagConstraints help
By noobgrammer in forum New To JavaReplies: 5Last Post: 07-03-2010, 04:12 AM -
how to build reuasble swing buttons
By adi in forum AWT / SwingReplies: 3Last Post: 12-28-2008, 05:04 PM -
Searching a string from a text file using Swing Buttons
By pradeep1_mca@yahoo.com in forum AWT / SwingReplies: 2Last Post: 09-15-2008, 09:50 AM -
GridBagConstraints
By Aswq in forum New To JavaReplies: 2Last Post: 07-21-2008, 09:08 PM -
Demonstration of various Swing buttons
By Java Tip in forum javax.swingReplies: 0Last Post: 06-26-2008, 07:37 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks