Get your CodeRanch badge!*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Absolute Positioning
 
Similar Threads
Absolute layout on nested panel
Problem in State Design Pattern
Writing to file problems
problem with handling the states of the events
Ohhhhh this has taken ALLLL DAY!