• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Underline first character of a JButton?

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I have set the mnemonic on a JButton but how do I underline the specified character?
Thanks for your help.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using JDK1.4.1_01 and it looks like setMnemotic( int ) automatically underlines the first occurance of the mnemotic character in the title of the button... You are using the appropriate KeyEvent.VK_* for the parameters, right? So I'm not sure what you're having problems with... Could you provide an example of the code that doesn't work?
 
Adam Till
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I have managed to get it working with the following:-
String localLabel = "<html><a style='text-decoration:underline'>L</a>ocal Connection</html>";
JButton local = new JButton(localLabel);
It did not seem to add the underline automatically, I am using the same JDK. So I used HTML, several HTML tags are being deprecated so I had to use CSS inline. Is this the only way I wonder?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmmm... it's working for me to do :



What OS are you using, and what look and feel?
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have a second button which starts with "L" and you want to use to underline "L" would not work for the second button, HTML is the way to go.
Thank you
Jawad
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ummm... sorry, Jawad... but it's working for me in that case, too...

The mnemotic only actually works for the last component it was applied to, but the appropriate character on all the components it was applied to are underlined...

 
Jawad Kakar
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, for correcting me.
Jawad
 
Adam Till
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right, figured the problem. My platform is XP and when my app starts I set the look and feel to getSystemLookAndFeelClassName(). If I remove this then yes it works.
I am still getting used to the 'look and feel' aspects, but what I was trying to do was use any systems default (for no other reason than scientific purposes so could just use the java defualt).
Any comments?
Thanks all,
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's weird... the Windows Look & Feel doesn't underline at all... Guess it's just yet another way Windows is broken...
 
Do Re Mi Fa So La Tiny Ad
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic