• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Absolute Positioning

 
Brian Winkler
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
panel.setLayout(null);
panel = new JPanel();

reverse the lines
 
Brian Winkler
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic