Как определить ключи
Я хочу создать таблицу, в которой я хочу настроить горячие клавиши.
У меня есть эта простая таблица:
public static final String Column1MapKey = "A";
public static final String Column2MapKey = "B";
private ObservableList generateDataInMap() {
int max = 110;
ObservableList allData = FXCollections.observableArrayList();
for (int i = 1; i < max; i++) {
Map 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 firstDataColumn = new TableColumn("Actions");
TableColumn 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
cellFactoryForMap = new Callback() {
@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;
}
Я хочу, чтобы при нажатии на строку во втором столбце, чтобы получить комбинацию клавиш, которые я буду нажимать, а затем использовать эти клавиши для активации сочетаний клавиш. Любой пример будет полезен.
Таблица P.S с командами:
public static final String Column1MapKey = "A";
public static final String Column2MapKey = "B";
private ObservableList generateDataInMap() {
int max = 110;
ObservableList allData = FXCollections.observableArrayList();
for (int i = 1; i < max; i++) {
Map 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 firstDataColumn = new TableColumn("Actions");
TableColumn 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
cellFactoryForMap = new Callback() {
@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;
}