• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Button Size

 
Kevin Broderick
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • 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
 
Carlos Morillo
Ranch Hand
Posts: 221
Java Python Scala
  • Mark post as helpful
  • send pies
  • 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.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks lads
 
Kevin Broderick
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • 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: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic