setMnemonic

Status
Nicht offen für weitere Antworten.

padde479

Bekanntes Mitglied
Hi,

ich möchte in einem Menüeintrag einen Mnemonic setzen. Das erledige ich wie folgt:
Code:
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

Top Contributor
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
 
Status
Nicht offen für weitere Antworten.
Ähnliche Java Themen

Ähnliche Java Themen

Neue Themen


Oben