• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Resizing JLabel to fit text

 
Sebastiaan Kortleven
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sebastiaan Kortleven
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic