aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Absolute Positioning Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Absolute Positioning" Watch "Absolute Positioning" New topic
Author

Absolute Positioning

Brian Winkler
Greenhorn

Joined: Jun 05, 2012
Posts: 16
I have this test code I am trying with a panel that uses absolute positioning, but when I run the code, it doesn't like the setLayout(null) line. Can one of you please look at it and let me know what I have wrong? Thanks.

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
panel.setLayout(null);
panel = new JPanel();

reverse the lines
Brian Winkler
Greenhorn

Joined: Jun 05, 2012
Posts: 16
Michael Dunn wrote:panel.setLayout(null);
panel = new JPanel();

reverse the lines


ha, I just figured it out at the same time you answers that. Thank you.

One other question, I am trying to take that panel and insert it into a JFrame with a border layout as the SOUTH panel, but when I run the code, nothing shows. Should I be able to do this? or am I doing something wrong?

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
because 'panel' is a null layout it has no
preferred size i.e. a preferred size (0,0)

BorderLayout uses the preferred size to
layout the components, so add
panel.setPreferredSize(new Dimension(400,100));
where 400,100 can be anything you want.
then use
frame.pack();
instead of
frame.setSize();
Brian Winkler
Greenhorn

Joined: Jun 05, 2012
Posts: 16
Michael Dunn wrote:because 'panel' is a null layout it has no
preferred size i.e. a preferred size (0,0)

BorderLayout uses the preferred size to
layout the components, so add
panel.setPreferredSize(new Dimension(400,100));
where 400,100 can be anything you want.
then use
frame.pack();
instead of
frame.setSize();


I love this site. This worked perfectly. Thanks again for your help!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Absolute Positioning