views:

167

answers:

1

Hi all,

I have a JButton that is constructed using an Action and this action has a name that is contains html.

I then go about setting the mnemonic on the JButton by first parsing out html to get the first character in the name.

For example, the JButton name might be "<html>Test<br>Button</html>", so after parsing the html the mnemonic key should be "T".

So now when the JButton is rendered I can push alt-T to activate the button, however the underline mnemonic indicator on the T is not present.

Would anyone know a way to get this to occur?

+1  A: 
sateesh
Sorry I guess I should have been more clear. I have a framework for displaying error messages that have button in my app, so for the same of reusable code what I do is parse the html (in your case "<html><b><u>P</u>ress</b></html>") in order to find the character on which the mnemonic should be set (in this case P).
Denis Sadowski
If there was no html in the JButton name, and you set a mnemonic then it would underline the P on its own. However in this case it seems that you had to add html formatting to do this yourself. Is there no way to make the JButton do the underlining itself, as opposed to having to put it in the html.As it might be the case that I have two buttons in my error framework, "<html>Press<br>Me</html>" and "<html>Push<br>Me</html>". In which case one of them will have a differnt mnemonic set for it, and I would prefer not to couple the underlining to the html.
Denis Sadowski
I didn't get your question.the code "jButton.setMnemonic('P');" already sets the underline in P. The html is unnessecary in this case.
marionmaiden
I've found that if I have: b1 = new JButton("<html><b>Press</b><br>Button</html>"); b1.setMnemonic(KeyEvent.VK_P); That the P will not be underlined.
Denis Sadowski