• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Button Size

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 221
Scala Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kevin,

I simply used a seperate panel for my buttons with FlowLayout as a layout manager.

Kind regards,
Roel
 
Kevin Broderick
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks lads
 
Kevin Broderick
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic