my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes BorderLayout JLabel size problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "BorderLayout JLabel size problem" Watch "BorderLayout JLabel size problem" New topic
Author

BorderLayout JLabel size problem

John Davis
Ranch Hand

Joined: Nov 02, 2000
Posts: 189
I am using a BorderLayout for two components: a JLabel at "EAST" and a JList at WEST. The JLabel was constructed with an ImageIcon. The problem is that the resulting JLabel is very wide. on Windows 98 SE clients, the contentPane gives 50% space to the "East" component and 50% space to the "West" component.
On a Windows Millenium Edition client machine, the content pane uses almost all the space for "east" component, (the JLabel with the image) and only 1% to the JList. Just the very thin edge of the JList is displayed.
I have looked for methods in the various objects whereby I might restrict the size or display of a given component but so far, have not found anything to help out with this problem.
Any suggestions?
i.e. I need to keep my <applet> tags width parameter setting the way it is which restricts the overall size of the applet display.
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi JOhn,
Have you thought about using multi-lined label to avoid the long label? You can do it with the following HTML stuff:
label.setText( "< html >First line< p >Second line< /html >" );
Regards,
Manfred.
John Davis
Ranch Hand

Joined: Nov 02, 2000
Posts: 189
Manfred,
Thanks for the tip, its good to know about these things.
However, my label doesn't even have any text. The constructor for the JLabel is:
final JLabel photoLabel = new JLabel();
The JLabel content comes from:
photoLabel.setIcon(new ImageIcon(photoURL) );
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi JOhn,
Just so we understand the same thing here. Your layout:
list | icon
This means that you have nothing in the center. The way a BorderLayout works is:
Fit North component by asking about height and stretching width.
Fit South component by asking about height and stretching width.
Fit West component by asking about width and stretching height.
Fit East component by asking about width and stretching height.
Center gets any leftover room.
Use the program below, replacing the image file with yours to see how the layout works.

On my systems, I get the list against the left edge and wide enough for its contents, and the image on the right wide enough for its contents, with a large red center area.
Regards,
Manfred.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: BorderLayout JLabel size problem