aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Resizing JLabel to fit text Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Resizing JLabel to fit text" Watch "Resizing JLabel to fit text" New topic
Author

Resizing JLabel to fit text

Sebastiaan Kortleven
Ranch Hand

Joined: Mar 12, 2004
Posts: 81
Hi there,
Is there any way to resize a JLabel to fit it's text?
I'm adding several JLabels to a GridBagLayout, but they have a standard size (which is too large). I could manually resize them all, but it would be much nicer if there was some kind of method I could invoke on them (then changing the labels text would not mean more experimenting with label sizes)...
Tnx!
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Post your code for where you are adding the JLabels to the container with GridBagLayout. The constraints you have set for the GridBagLayout are mainly what is affecting the size of the JLabels in this case.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Sebastiaan Kortleven
Ranch Hand

Joined: Mar 12, 2004
Posts: 81
Here goes:

I've got several labels with a gridx=0, but a different gridy. None of these labels are as large as the width of that 'column'...
I also got a JTable spanning several 'rows' and 'columns' in the GridBagLayout.. I don't know if he havs something to do with it..
Check out this view... the red lines show the 'columns' I defined...
I could do an entire listing of the code, but there are quite a few objects in this pane..
view
tnx!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Resizing JLabel to fit text
 
Similar Threads
best layout to use
JLabel centered in a JPanel
can we start one applet from another applet
Set size for JOptionPane?
Resize width only?