The moose likes Swing / AWT / SWT / JFace and the fly likes JLabel size Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT / JFace
Reply Bookmark "JLabel size" Watch "JLabel size" New topic
Author

JLabel size

Paul Keohan
Ranch Hand

Joined: Mar 15, 2000
Posts: 411
How do I make a JLabel 40 characters (for example) wide? If I instantiate it with a huge long empty string it still scrunches up to a relatively small size. When I setText() into it, it sticks it so far over to the right of the JLabel, I usually can't see it.
Thanks!
Paul
Jeff Wisard
Ranch Hand

Joined: Jan 07, 2002
Posts: 89
I would play around with alternate layout managers if I were you. Although it is the most complex, GridBagLayout is the most powerful layout manager and you could definetely work this out using one.
You could probably do this also with BorderLayout, GridLayout, or even a FlowLayout. You may have to use multiple layouts to get the desired effect. Just play with it!
Hope this helps!


Jeff Wisard<br />Sun Certified Java Programmer (Java 2)<br />Sun Certified Web Component Developer
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
Try setMinimumSize() it won't let it go less than that size. setPreferredSize() might work.
 
 
subject: JLabel size
 
Threads others viewed
BorderLayout
JLabel centered in a JPanel
JLabel
how to size a label?
setPreferredSize trouble
developer file tools