# setMnemonic



## padde479 (30. Mai 2007)

Hi,

ich möchte in einem Menüeintrag einen Mnemonic setzen. Das erledige ich wie folgt:

```
private JMenuItem getExit() {
		item = new JMenuItem("Beenden");
		item.addActionListener(this);
		item.setMnemonic('e');
		item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q,
				Event.CTRL_MASK));

		return item;
	}
```
Dadurch wird das erste 'e' unterstrichen. Wie schaffe ich aber, dass der vorletzte Buchstabe unterstrichen wird? Kann ich das beeinflußen?

Gruß
Padde


----------



## EOB (30. Mai 2007)

aus der API:
_
Provides a hint to the look and feel as to which character in the text should be decorated to represent the mnemonic. Not all look and feels may support this. A value of -1 indicates either there is no mnemonic, the mnemonic character is not contained in the string, or the developer does not wish the mnemonic to be displayed.

The value of this is updated as the properties relating to the mnemonic change (such as the mnemonic itself, the text...). You should only ever have to call this if you do not wish the default character to be underlined. For example, if the text was 'Save As', with a mnemonic of 'a', and you wanted the 'A' to be decorated, as 'Save As', you would have to invoke setDisplayedMnemonicIndex(5) after invoking setMnemonic(KeyEvent.VK_A). _

grüße


----------



## padde479 (30. Mai 2007)

Danke,

wer lesen kann ist doch echt im Vorteil  

Gruß
Padde


----------



## EOB (31. Mai 2007)

:wink:  :toll:


----------

