設Java字符串操作代碼爲您執行此操作。
例如,假設操作的數組:
private Action[] textActions = { new DefaultEditorKit.CutAction(),
new DefaultEditorKit.CopyAction(), new DefaultEditorKit.PasteAction(), };
- 獲取經由Action的
getValue(...)
方法的動作的原始名稱。 substring(0, value.indexOf("-"));
- 再次使用的子開始用大寫字母的字符串:
- 將名稱改爲由歌廳開始於字符串的開始和結束
"-"
的子擺脫-to-clipboard
部分。
- 使用Action
putValue(...)
方法將Action的名稱設置爲我們的新值。
例如:
private Action[] textActions = { new DefaultEditorKit.CutAction(),
new DefaultEditorKit.CopyAction(), new DefaultEditorKit.PasteAction(), };
public DisplayText(String title, String info) {
JMenu menu = new JMenu("Edit");
for (Action textAction : textActions) {
String value = textAction.getValue(AbstractAction.NAME).toString();
value = value.substring(0, value.indexOf("-"));
value = value.substring(0, 1).toUpperCase() + value.substring(1);
textAction.putValue(AbstractAction.NAME, value);
menu.add(new JMenuItem(textAction));
}
這是做到這一點的最好辦法。謝謝。 –
@ user3541786不客氣。 –