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 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
posted
1
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
posted
0
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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.