aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JButton resizing issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JButton resizing issue" Watch "JButton resizing issue" New topic
Author

JButton resizing issue

Richard Alves
Greenhorn

Joined: Mar 03, 2012
Posts: 12
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

Joined: Mar 03, 2012
Posts: 12
Even when I remove the last setBounds() the next button up (27) fills the container.
Richard Alves
Greenhorn

Joined: Mar 03, 2012
Posts: 12
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

Joined: May 03, 2008
Posts: 4664
    
    5

You should learn to use layout managers instead of messing around with setBounds(...).
http://docs.oracle.com/javase/tutorial/uiswing/layout/index.html


luck, db
There are no new questions, but there may be new answers.
Richard Alves
Greenhorn

Joined: Mar 03, 2012
Posts: 12
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

Joined: Mar 28, 2012
Posts: 859

Darryl is correct.
With one line ...



after:


Run it and see what happens.

WP
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4664
    
    5

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

Joined: Mar 03, 2012
Posts: 12
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

Joined: Mar 03, 2012
Posts: 12
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

Joined: May 03, 2008
Posts: 4664
    
    5

http://mindprod.com/jgloss/layout.html#NULLLAYOUTS
http://mindprod.com/jgloss/gotchas.html#NULLLAYOUT
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JButton resizing issue