I want to create a table in which I want to configure hotkeys.
I have this simple table:
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; }
I want when I click on a row in the second column to get the key combination that I press, and then use these keys to activate keyboard shortcuts. Any example would be helpful.
PS Table with commands:
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; }