Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JButton resizing issue

 
Richard Alves
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am directly sizing and locating JButtons in an app and for some reason the last button that is added to the container always fills the container.

Here is the code


The last button marked by the comment 28 should be the correct button (button 28 index 27) so I'm not sure whats going on. Thanks for any help.
 
Richard Alves
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even when I remove the last setBounds() the next button up (27) fills the container.
 
Richard Alves
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I fixed it by adding a blank button then removing it. It makes the GUI come out how I want but I feel like there should be a better way to do this.
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should learn to use layout managers instead of messing around with setBounds(...).
http://docs.oracle.com/javase/tutorial/uiswing/layout/index.html
 
Richard Alves
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know how to use layout managers. In this case because of how the buttons were set up I decided it would be better to use a null manager.
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl is correct.
With one line ...



after:


Run it and see what happens.

WP
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Richard Alves wrote:I know how to use layout managers. In this case because of how the buttons were set up I decided it would be better to use a null manager.


Your code, and your problem, and the 'solution' all show that you don't know how to use BorderLayout and/or don't know which components have a default layout manager set, and which layout manager. That's knowledge you can't go far without.

I repeat my recommendation to learn how to use layout managers.
 
Richard Alves
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I sorta understand layout managers in that I can use them. I asked in a previous post how to best layout buttons in a unique pattern, and was told a null layout may be the best in this case. Would you know any documentation about when a null layout is a good decision?

Thanks for the info so far!
 
Richard Alves
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William P O'Sullivan wrote:Darryl is correct.
With one line ...



Run it and see what happens.

WP


>_< I forgot to set the layout manager to null. Thanks!
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://mindprod.com/jgloss/layout.html#NULLLAYOUTS
http://mindprod.com/jgloss/gotchas.html#NULLLAYOUT
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic