GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes Using SpringLayout with JPanel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Using SpringLayout with JPanel" Watch "Using SpringLayout with JPanel" New topic
Author

Using SpringLayout with JPanel

Nicholas van Orton
Greenhorn

Joined: Aug 13, 2005
Posts: 17
Keeping in mind that I'm just a beginner, this one is a real head scratcher for me. Here's what I've got at the moment:



I add this JPanel to my Main class:



My dilemma is that when I add the ControlPane() object to the BorderLayout.SOUTH of the JFrame, nothing appears! Yet It works when the ControlPane() object is added to the BorderLayout.CENTER of the JFrame - which I would be doing if I didn't have anything else to add to the JFrame.

Any clues?

Thanks
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
add this line to ControlPane's constructor

setPreferredSize(new Dimension(725,50));
Nicholas van Orton
Greenhorn

Joined: Aug 13, 2005
Posts: 17
I've tried your solutions, and the JPanel is now appearing. However, the JSlider object is not appearing where its SpringLayout constraints say it should appear.

Any more clues?
[ April 14, 2006: Message edited by: Nicholas van Orton ]
Nicholas van Orton
Greenhorn

Joined: Aug 13, 2005
Posts: 17
I've had to remove the line "super(new SpringLayout());" and replaced it with "this.setLayout(layout);" at it works.

Any explanations as to why this is would be very much appreciated.

Thanks
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
it worked OK for me, as is, with the additional setPreferredSize line
ie with the "super(new SpringLayout());"

I'm using java 1.5.0_05, on winXP Pro
Nicholas van Orton
Greenhorn

Joined: Aug 13, 2005
Posts: 17
I'm using Java 1.5.0_05 on Mac OS X v10.4 - I would have thought that this shouldn't have made any difference.
 
GeeCON Prague 2014
 
subject: Using SpringLayout with JPanel