我想创建要在其中配置热键快捷方式的表。
我有这个简单的表:
public static final String Column1MapKey = "A";
public static final String Column2MapKey = "B";
private ObservableList<Map> generateDataInMap() {
int max = 110;
ObservableList<Map> allData = FXCollections.observableArrayList();
for (int i = 1; i < max; i++) {
Map<String, String> dataRow = new HashMap<>();
String value1 = "A" + i;
String value2 = "B" + i;
dataRow.put(Column1MapKey, value1);
dataRow.put(Column2MapKey, value2);
allData.add(dataRow);
}
return allData;
}
public TabPane hotKeysContent(){
TableColumn<Map, String> firstDataColumn = new TableColumn<>("Actions");
TableColumn<Map, String> secondDataColumn = new TableColumn<>("Shortcut");
firstDataColumn.setCellValueFactory(new MapValueFactory(Column1MapKey));
firstDataColumn.setMinWidth(230);
secondDataColumn.setCellValueFactory(new MapValueFactory(Column2MapKey));
secondDataColumn.setMinWidth(230);
TableView table_view = new TableView<>(generateDataInMap());
table_view.setPadding(new Insets(5, 5, 5, 5));
table_view.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); // Autoresize when window size is changed
table_view.setEditable(true);
table_view.getSelectionModel().setCellSelectionEnabled(true);
table_view.getColumns().setAll(firstDataColumn, secondDataColumn);
Callback<TableColumn<Map, String>, TableCell<Map, String>>
cellFactoryForMap = new Callback<TableColumn<Map, String>,
TableCell<Map, String>>() {
@Override
public TableCell call(TableColumn p) {
return new TextFieldTableCell(new StringConverter() {
@Override
public String toString(Object t) {
return t.toString();
}
@Override
public Object fromString(String string) {
return string;
}
});
}
};
firstDataColumn.setCellFactory(cellFactoryForMap);
secondDataColumn.setCellFactory(cellFactoryForMap);
return null;
}
当我单击第二列中的一行时,我希望获得我将按下的键组合,然后使用这些键来激活键盘快捷键。任何示例都会有所帮助。
带有命令的 PS 表:
public static final String Column1MapKey = "A";
public static final String Column2MapKey = "B";
private ObservableList<Map> generateDataInMap() {
int max = 110;
ObservableList<Map> allData = FXCollections.observableArrayList();
for (int i = 1; i < max; i++) {
Map<String, String> dataRow = new HashMap<>();
String value1 = "A" + i;
String value2 = "B" + i;
dataRow.put(Column1MapKey, value1);
dataRow.put(Column2MapKey, value2);
allData.add(dataRow);
}
return allData;
}
public TabPane hotKeysContent(){
TabPane tabPane = new TabPane();
//tabPane.setStyle("-fx-font-size: 13pt;"); // Set size of the tab name
Tab tabA = new Tab();
Label tabALabel = new Label("Shortcuts");
//tabALabel.setStyle("-fx-font-size: 12pt;"); // Set size of the tab name
tabA.setGraphic(tabALabel);
tabA.setClosable(false); // da se mahne opciqta da se zatvarq tab
TableColumn<Map, String> firstDataColumn = new TableColumn<>("Actions");
TableColumn<Map, String> secondDataColumn = new TableColumn<>("Shortcut");
firstDataColumn.setCellValueFactory(new MapValueFactory(Column1MapKey));
firstDataColumn.setMinWidth(230);
secondDataColumn.setCellValueFactory(new MapValueFactory(Column2MapKey));
secondDataColumn.setMinWidth(230);
TableView table_view = new TableView<>(generateDataInMap());
table_view.setPadding(new Insets(5, 5, 5, 5));
table_view.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); // Autoresize when window size is changed
table_view.setEditable(true);
table_view.getSelectionModel().setCellSelectionEnabled(true);
table_view.getColumns().setAll(firstDataColumn, secondDataColumn);
Callback<TableColumn<Map, String>, TableCell<Map, String>>
cellFactoryForMap = new Callback<TableColumn<Map, String>,
TableCell<Map, String>>() {
@Override
public TableCell call(TableColumn p) {
return new TextFieldTableCell(new StringConverter() {
@Override
public String toString(Object t) {
return t.toString();
}
@Override
public Object fromString(String string) {
return string;
}
});
}
};
firstDataColumn.setCellFactory(cellFactoryForMap);
secondDataColumn.setCellFactory(cellFactoryForMap);
tabA.setContent(table_view);
tabPane.getTabs().add(tabA);
return tabPane;
}