| Author |
Button Size
|
Kevin Broderick
Ranch Hand
Joined: Jul 19, 2009
Posts: 39
|
|
Hello All,
I have a problem with the gui main window layout. On the centre of the screen is a JTable and below to the right are two buttons called Search and Book. The trouble is, the size of the width of the search button is longer than the Book button. I tried getting the size of the search button and then passing this down to the book button but this does not change the width of the book button.
Any ideas as to what to do?
Thanks
|
 |
Carlos Morillo
Ranch Hand
Joined: Jun 06, 2009
Posts: 209
|
|
Read the Andrew Monkhouse's book GUI chapter.
You need to play with several panels and Layout managers to get rid of that effect.
HTH,
Carlos.
|
SCSA, OCA, SCJP 5.0, SCJD http://www.linkedin.com/in/carlosamorillo
|
 |
Roel De Nijs
Bartender
Joined: Jul 19, 2004
Posts: 3820
|
|
Hi Kevin,
I simply used a seperate panel for my buttons with FlowLayout as a layout manager.
Kind regards,
Roel
|
SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
|
 |
Kevin Broderick
Ranch Hand
Joined: Jul 19, 2009
Posts: 39
|
|
Thanks lads
|
 |
Kevin Broderick
Ranch Hand
Joined: Jul 19, 2009
Posts: 39
|
|
I finally found this out.
If you are creating two buttons with the titles OK and Cancel, as a default each of the buttons will size accordingly to the length of their titles. To remedy this, for each of the buttons, call its setPreferedSize method passing in dimensions of width and height to be of the same lenght as each other and buttons OK and Cancel will be of the same size.
I'm delighted as to how easy this was, and I'm replying to this topic in the case that any of the other ranchers are having the same trouble.
Just my 2 cents.
Kevin
|
 |
Roel De Nijs
Bartender
Joined: Jul 19, 2004
Posts: 3820
|
|
Hi Kevin,
I don't know if buttons having same width is something where you want to add extra lines for. I just stuck with the FlowLayout and the width depending on the caption of the button.
Kind regards,
Roel
|
 |
 |
|
|
subject: Button Size
|
|
|