I'm looking for a way to prevent the end user to select text displayed in a JLabel with the mouse (my app is actually running on a touchscreen with no mouse). I could not find any method like "setSelectable(boolean b)" in the JLabel javadoc. Anybody has an idea?
Actually, the component needs not to be a JLabel, I just need to display some text.
Thanks in advance
It is a mistake to think you can solve any major problems just with potatoes.<br />--Douglas Adams
I didn't think you could do anything with the text in a JLabel in the first place . . . It is all set up by the app and controlled from inside the app. That si why they haven't provided a setSelectable(boolean) method.
Joined: Sep 16, 2005
Originally posted by Campbell Ritchie: I didn't think you could do anything with the text in a JLabel in the first place . . . It is all set up by the app and controlled from inside the app. That si why they haven't provided a setSelectable(boolean) method.
The only direct approach I can think of is subclassing the LabelUI or changing some of its default property settings, but that's beyond my meager abilities.
Joined: Apr 10, 2006
Just curious: what's so bad about selecting text?
Well, it just looks ugly on my applicaton !
Here's the long story:
This JLabel is part of a ZoneButton, which is a kind of complex button made of a JPanel containing an Icon on the right, the JLabel on the left and another Icon as background. This ZoneButton acts as a toggle button (the background image changes upon selection/deselection), and the ImageIcon changes depending on the "state" of the zone represented by the ZoneButton (there are 4 possible states at the moment).
The text in the JPanel is configured by the end-user, so using a rendered image is not an option.
The whole stuff runs on a touchscreen mini-pc with no mouse or keyboard. What happens is that when the user drags its finger, the text on the ZoneButton gets selected and, well, it does not look nice.