好吧,这是一个有趣的问题!你是对的,你不能直接在选项卡上设置助记符。但是您可以将组件添加为支持助记符功能的 Tabs 图形:
private class MTab extends Tab
{
public MTab(String pText)
{
super();
Button fakeLabel = new Button(pText);
fakeLabel.setMnemonicParsing(true);
fakeLabel.getStyleClass().clear();
setGraphic(fakeLabel);
fakeLabel.setOnAction(ev -> {
if (getTabPane() != null) {
getTabPane().getSelectionModel().select(this);
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
使用此选项卡:
TabPane tabs = new TabPane();
tabs.getTabs().add(new MTab("_this is a test"));
tabs.getTabs().add(new MTab("t_his is a test"));
tabs.getTabs().add(new MTab("th_is is a test"));
Run Code Online (Sandbox Code Playgroud)
将使您的标签可通过快捷方式切换。
| 归档时间: |
|
| 查看次数: |
390 次 |
| 最近记录: |