Forums Register Login

JLabel size

+Pie Number of slices to send: Send
Hi. I have created 4 JLabels, and I want them to remain the same size when they are initialized and when data is put into them. My Labels start out with no text. I have tried both setPreferredSize() and setSize() to get the Labels to the size I want, but it doesn't work. When I put a long empty string in the text of the label, they are the size I want. However, once I set the text of them, if the text is not the same size of the label, it shortens the label.
Could someone please help me understand what I am doing wrong?
Thanks in advance!
+Pie Number of slices to send: Send
You might try setMinimumSize() and setMaximumSize() with setPreferredSize().
+Pie Number of slices to send: Send
You could always put the current JLabel inside a JPanel and put the new JPanel wherever the current JLabel resides. Set the layout of the new JPanel to BorderLayout and add the JLabel component to the JPanel with Center position. The JLabel should completely fill the JPanel due to this layout. The size should remain whatever size you make the JPanel as long as you don't add any other components to the JPanel (to North, South, East or West).
Lon Allen
+Pie Number of slices to send: Send
Thanks for the help guys! I tried setting the maximum size to the preferred size and that worked!
machines help you to do more, but experience less. Experience this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1234 times.
Similar Threads
GridBagLayout question
ideas wanted on making this custom JTable cell renderer more efficient
Swing HELP!
Layout problem with the gaps
How can I align elements that are in different <div>'s?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 16:35:07.