I have a JLabel
with unknown content and I have two things I want to do:
- I want to set a maximum or perhaps even static width of the label. And if the text is larger than the label it would somply shorten it, like this:
Verylonglabel
becomes
Veryl
Is it a bad idea to use static width on components in a gui? If that is the case, what is the alternative? Please give me advice!
- When you hover over the label I want a tooltip with the full length string to appear. So in our case, if i hover over the label that says "Veryl", a tooltip displaying "Verylonglabel" would appear. However, it should display a tooltip with the full length string even if it was not shortened.
Help with either of these is greatly appreciated.
So far I've just messed around a bit and tried things like this without sucess. It doesn't seem to care about the size at all.
JLabel label = new JLabel("Verylonglabel");
label.setSize(15, 5);
Best regards, Goatcat