How would one test if a JLabel, with set size, wouldn't be able to display all the text that it set to display?
Asked
Active
Viewed 105 times
1 Answers
5
- Make another label that you do not set the size of.
- Add the same text to the 2nd label.
- Call for the preferred size.
- If it is larger than the set size, your text will be truncated.
But the most sensible solution is not to set the sizes of labels in the first place.
See also this example.

Community
- 1
- 1

Andrew Thompson
- 168,117
- 40
- 217
- 433
-
2Yes; let the label to the work, as seen [here](http://stackoverflow.com/a/3597688/230513). – trashgod Jun 01 '12 at 04:19
-
1@trashgod Always nice to see an example of yours that I've yet had the opportunity to up-vote. – Andrew Thompson Jun 01 '12 at 04:23
-
1I am pleased to endorse your [sensible solution](http://stackoverflow.com/q/7229226/230513). – trashgod Jun 01 '12 at 04:35