• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

howto prevent JLabel text selection

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

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
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just curious: what's so bad about selecting text?

You could render the text to a BufferedImage and display that, but there must be a simpler way with a JLabel.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Swing/AWT forum.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Rodrigo Alvarez
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since when can you "select" text in a JLabel?
 
That feels good. Thanks. Here's a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic