File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Underline first character of a JButton?

 
Adam Till
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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 Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmmm... it's working for me to do :



What OS are you using, and what look and feel?
 
Jawad Kakar
Ranch Hand
Posts: 82
  • 0
  • Mark post as helpful
  • send pies
  • 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 Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, for correcting me.
Jawad
 
Adam Till
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • 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 Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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...
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic