如何使用箭头按钮在 TableView 的编辑模式下遍历单元格

我想使用箭头/enter键遍历 中的单元格,但是,如果我尝试在我的自定义EditCell类中实现它,它似乎不起作用。有没有办法做到这一点?我尝试过在 上使用侦听器,但它实际上并没有在实际单元格中启动焦点。TableViewTextField


这是我的代码:


测试人员.java


package tester;


import javafx.application.Application;

import javafx.scene.Scene;

import javafx.scene.control.TableCell;

import javafx.scene.control.TableColumn;

import javafx.scene.control.TableRow;

import javafx.scene.control.TableView;

import javafx.scene.layout.HBox;

import javafx.stage.Stage;

import javafx.util.Callback;


public class Tester extends Application

{


    @Override

    public void start(Stage primaryStage)

    {


        TableView<LineItem> table = new TableView<>();


        Callback<TableColumn<LineItem, String>, TableCell<LineItem, String>> textFactoryEditable = (TableColumn<LineItem, String> p) -> new EditableTextCell();


        TableColumn<LineItem, String> column1 = new TableColumn<>("Test1");

        column1.setCellValueFactory(cellData -> cellData.getValue().getString1Property());

        column1.setEditable(true);

        column1.setCellFactory(textFactoryEditable);


        table.getColumns().add(column1);


        TableColumn<LineItem, String> column2 = new TableColumn<>("Test2");

        column2.setCellValueFactory(cellData -> cellData.getValue().getString2Property());

        column2.setEditable(true);

        column2.setCellFactory(textFactoryEditable);


        table.getColumns().add(column2);


        table.getItems().add(new LineItem());

        table.getItems().add(new LineItem());

        table.getItems().add(new LineItem());


        table.setPrefWidth(500);


        HBox root = new HBox();

        root.getChildren().addAll(table);


        Scene scene = new Scene(root, 500, 500);


        primaryStage.setTitle("Hello World!");

        primaryStage.setScene(scene);

        primaryStage.show();

    }


    /**

     * @param args the command line arguments

     */

    public static void main(String[] args)

    {

        launch(args);

    }


}


喵喵时光机
浏览 67回答 2
2回答

动漫人物

行选择模式尽管我的评论,但看起来您并不需要为此启用单元格选择。从CheckBoxTableCell的实现中汲取灵感,您的自定义应该采用某种形式的回调来获取模型属性;它还可能需要一个&nbsp;StringConverter,允许您使用不仅仅包含 s 的 。下面是一个示例:TableCellTableCellStringimport java.util.Objects;import java.util.function.IntFunction;import javafx.beans.binding.Bindings;import javafx.beans.property.ObjectProperty;import javafx.beans.property.Property;import javafx.beans.property.SimpleObjectProperty;import javafx.scene.control.TableCell;import javafx.scene.control.TableColumn;import javafx.scene.control.TableView.TableViewFocusModel;import javafx.scene.control.TextField;import javafx.scene.input.KeyEvent;import javafx.util.Callback;import javafx.util.StringConverter;import javafx.util.converter.DefaultStringConverter;public class CustomTableCell<S, T> extends TableCell<S, T> {&nbsp; &nbsp; public static <S> Callback<TableColumn<S, String>, TableCell<S, String>> forTableColumn(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IntFunction<Property<String>> extractor) {&nbsp; &nbsp; &nbsp; &nbsp; return forTableColumn(extractor, new DefaultStringConverter());&nbsp; &nbsp; }&nbsp; &nbsp; public static <S, T> Callback<TableColumn<S, T>, TableCell<S, T>> forTableColumn(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IntFunction<Property<T>> extractor, StringConverter<T> converter) {&nbsp; &nbsp; &nbsp; &nbsp; Objects.requireNonNull(extractor);&nbsp; &nbsp; &nbsp; &nbsp; Objects.requireNonNull(converter);&nbsp; &nbsp; &nbsp; &nbsp; return column -> new CustomTableCell<>(extractor, converter);&nbsp; &nbsp; }&nbsp; &nbsp; private final ObjectProperty<IntFunction<Property<T>>> extractor = new SimpleObjectProperty<>(this, "extractor");&nbsp; &nbsp; public final void setExtractor(IntFunction<Property<T>> callback) { extractor.set(callback); }&nbsp; &nbsp; public final IntFunction<Property<T>> getExtractor() { return extractor.get(); }&nbsp; &nbsp; public final ObjectProperty<IntFunction<Property<T>>> extractorProperty() { return extractor; }&nbsp; &nbsp; private final ObjectProperty<StringConverter<T>> converter = new SimpleObjectProperty<>(this, "converter");&nbsp; &nbsp; public final void setConverter(StringConverter<T> converter) { this.converter.set(converter); }&nbsp; &nbsp; public final StringConverter<T> getConverter() { return converter.get(); }&nbsp; &nbsp; public final ObjectProperty<StringConverter<T>> converterProperty() { return converter; }&nbsp; &nbsp; private Property<T> property;&nbsp; &nbsp; private TextField textField;&nbsp; &nbsp; public CustomTableCell(IntFunction<Property<T>> extractor, StringConverter<T> converter) {&nbsp; &nbsp; &nbsp; &nbsp; setExtractor(extractor);&nbsp; &nbsp; &nbsp; &nbsp; setConverter(converter);&nbsp; &nbsp; &nbsp; &nbsp; // Assumes this TableCell will never become part of a different TableView&nbsp; &nbsp; &nbsp; &nbsp; // after the first one. Also assumes the focus model of the TableView will&nbsp; &nbsp; &nbsp; &nbsp; // never change. These are not great assumptions (especially the latter),&nbsp; &nbsp; &nbsp; &nbsp; // but this is only an example.&nbsp; &nbsp; &nbsp; &nbsp; tableViewProperty().addListener((obs, oldTable, newTable) ->&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; newTable.getFocusModel().focusedCellProperty().addListener((obs2, oldPos, newPos) -> {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (getIndex() == newPos.getRow() && getTableColumn() == newPos.getTableColumn()) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; textField.requestFocus();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; })&nbsp; &nbsp; &nbsp; &nbsp; );&nbsp; &nbsp; }&nbsp; &nbsp; @Override&nbsp; &nbsp; protected void updateItem(T item, boolean empty) {&nbsp; &nbsp; &nbsp; &nbsp; super.updateItem(item, empty);&nbsp; &nbsp; &nbsp; &nbsp; if (empty) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setText(null);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setGraphic(null);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cleanUpProperty();&nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initializeTextField();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cleanUpProperty();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; property = getExtractor().apply(getIndex());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Bindings.bindBidirectional(textField.textProperty(), property, getConverter());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setGraphic(textField);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (getTableView().getFocusModel().isFocused(getIndex(), getTableColumn())) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; textField.requestFocus();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; private void cleanUpProperty() {&nbsp; &nbsp; &nbsp; &nbsp; if (property != null) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Bindings.unbindBidirectional(textField.textProperty(), property);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; property = null;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; private void initializeTextField() {&nbsp; &nbsp; &nbsp; &nbsp; if (textField == null) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; textField = new TextField();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; textField.addEventFilter(KeyEvent.KEY_PRESSED, this::processArrowKeys);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; textField.focusedProperty().addListener((observable, wasFocused, isFocused) -> {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (isFocused) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getTableView().getFocusModel().focus(getIndex(), getTableColumn());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; private void processArrowKeys(KeyEvent event) {&nbsp; &nbsp; &nbsp; &nbsp; if (event.getCode().isArrowKey()) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; event.consume();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TableViewFocusModel<S> model = getTableView().getFocusModel();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; switch (event.getCode()) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case UP:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; model.focusAboveCell();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case RIGHT:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; model.focusRightCell();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case DOWN:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; model.focusBelowCell();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case LEFT:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; model.focusLeftCell();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; default:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw new AssertionError(event.getCode().name());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getTableView().scrollTo(model.getFocusedCell().getRow());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getTableView().scrollToColumnIndex(model.getFocusedCell().getColumn());&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}这个例子并不详尽,并且做出了不能保证的假设,但它只是一个例子,所以我把任何调整留给你。其中一个改进可能是以某种方式包含文本格式化程序。也就是说,我相信它提供了您正在寻找的基本功能。要使用此单元格,您只需将 每个 的 设置。没有必要设置,这样做实际上可能是有害的,这取决于如何被调用。基本上,它看起来像这样:cellFactoryTableColumncellValueFactoryupdateItemTableView<YourModel> table = ...;TableColumn<YourModel, String> column = new TableColumn<>("Column");column.setCellFactory(CustomTableCell.forTableColumn(i -> table.getItems().get(i).someProperty()));table.getColumns().add(column);单元格选择模式但是,您尝试实现的此行为本身似乎基于单元格,因此启用单元格选择可能更好。这允许自定义人员将其行为基于选择而不是焦点,并将箭头键处理留给 .下面是上述示例的略微修改版本:TableCellTableViewimport java.util.Objects;import java.util.function.IntFunction;import javafx.beans.binding.Bindings;import javafx.beans.property.ObjectProperty;import javafx.beans.property.Property;import javafx.beans.property.SimpleObjectProperty;import javafx.event.EventDispatcher;import javafx.scene.control.TableCell;import javafx.scene.control.TableColumn;import javafx.scene.control.TextField;import javafx.scene.input.KeyEvent;import javafx.util.Callback;import javafx.util.StringConverter;import javafx.util.converter.DefaultStringConverter;public class CustomTableCell<S, T> extends TableCell<S, T> {&nbsp; &nbsp; /*&nbsp;&nbsp; &nbsp; &nbsp;* -- CODE OMITTED --&nbsp; &nbsp; &nbsp;*&nbsp; &nbsp; &nbsp;* The factory methods (forTableColumn) and properties (extractor&nbsp; &nbsp; &nbsp;* and converter) have been omitted for brevity. They are defined&nbsp; &nbsp; &nbsp;* and used exactly the same way as in the previous example.&nbsp; &nbsp; &nbsp;*/&nbsp; &nbsp; private Property<T> property;&nbsp; &nbsp; private TextField textField;&nbsp; &nbsp; public CustomTableCell(IntFunction<Property<T>> extractor, StringConverter<T> converter) {&nbsp; &nbsp; &nbsp; &nbsp; setExtractor(extractor);&nbsp; &nbsp; &nbsp; &nbsp; setConverter(converter);&nbsp; &nbsp; }&nbsp; &nbsp; @Override&nbsp; &nbsp; public void updateSelected(boolean selected) {&nbsp; &nbsp; &nbsp; &nbsp; super.updateSelected(selected);&nbsp; &nbsp; &nbsp; &nbsp; if (selected && !isEmpty()) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; textField.requestFocus();&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; @Override&nbsp; &nbsp; protected void updateItem(T item, boolean empty) {&nbsp; &nbsp; &nbsp; &nbsp; super.updateItem(item, empty);&nbsp; &nbsp; &nbsp; &nbsp; if (empty) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setText(null);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setGraphic(null);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clearProperty();&nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initializeTextField();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clearProperty();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; property = getExtractor().apply(getIndex());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Bindings.bindBidirectional(textField.textProperty(), property, getConverter());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setGraphic(textField);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (isSelected()) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; textField.requestFocus();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; private void clearProperty() {&nbsp; &nbsp; &nbsp; &nbsp; if (property != null) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Bindings.unbindBidirectional(textField.textProperty(), property);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; textField.setText(null);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; property = null;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; private void initializeTextField() {&nbsp; &nbsp; &nbsp; &nbsp; if (textField == null) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; textField = new TextField();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; textField.focusedProperty().addListener((observable, wasFocused, isFocused) -> {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (isFocused && !isSelected()) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getTableView().getSelectionModel().clearAndSelect(getIndex(), getTableColumn());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /*&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* TableView has key handlers that will select cells based on arrow keys being&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* pressed, scrolling to them if necessary. I find this mechanism looks cleaner&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* because, unlike TableView#scrollTo, it doesn't cause the cell to jump to the&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* top of the TableView.&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* The way this works is by bypassing the TextField if, and only if, the event&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* is a KEY_PRESSED event and the pressed key is an arrow key. This lets the&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* event bubble up back to the TableView and let it do what it needs to. All&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* other key events are given to the TextField for normal processing.&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* NOTE: The behavior being relied upon here is added by the default TableViewSkin&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*&nbsp; &nbsp; &nbsp; &nbsp;and its corresponding TableViewBehavior. This may not work if a custom&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*&nbsp; &nbsp; &nbsp; &nbsp;TableViewSkin skin is used.&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; EventDispatcher oldDispatcher = textField.getEventDispatcher();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; textField.setEventDispatcher((event, tail) -> {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (event.getEventType() == KeyEvent.KEY_PRESSED&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; && ((KeyEvent) event).getCode().isArrowKey()) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return event;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return oldDispatcher.dispatchEvent(event, tail);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}笔记使用(并且实际选择多个行/单元格)时,这两种方法都不起作用。SelectionMode.MULTIPLE上的集不能定义提取器。由于某种原因,这会导致表在您键入 时选择下一个右侧单元格。ObservableListTableViewTextField仅使用 JavaFX 12 测试了这两种方法。

叮当猫咪

多亏了Slaw,才想通了。首先启用单元格选择,table.getSelectionModel().setCellSelectionEnabled(true);然后在 EditableTextCell.java类中:&nbsp; &nbsp; &nbsp; &nbsp; this.focusedProperty().addListener((ObservableValue<? extends Boolean> o, Boolean oldValue, Boolean newValue) ->&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (newValue)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; textField.requestFocus();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; textField.focusedProperty().addListener((ObservableValue<? extends Boolean> o, Boolean oldValue, Boolean newValue) ->&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (newValue)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getTableView().getFocusModel().focus(getTableRow().getIndex(), getTableColumn());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; textField.setOnKeyPressed((KeyEvent ke) ->&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; switch (ke.getCode())&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case DOWN:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getTableView().getFocusModel().focusBelowCell();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ke.consume();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case ENTER:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getTableView().getFocusModel().focusBelowCell();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ke.consume();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case UP:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getTableView().getFocusModel().focusAboveCell();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ke.consume();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case RIGHT:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getTableView().getFocusModel().focusRightCell();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ke.consume();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case LEFT:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getTableView().getFocusModel().focusLeftCell();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ke.consume();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; default:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; });
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java