我正在尝试将焦点设置在 JTextPane 上,以便在窗口打开时可以立即使用键盘进行编辑。但是,我所做的一切似乎都没有让 JTextPane 专注于启动。这只是将 JavaFX 与 Swing 结合使用的问题吗?
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.embed.swing.SwingNode;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.ListView;
import javax.swing.*;
public class TestDialog {
@FXML
private ListView listView;
@FXML
private SwingNode node;
private ObservableList<Integer> obsList;
@FXML
public void initialize(){
JTextPane pane = new JTextPane();
SwingUtilities.invokeLater(() -> pane.requestFocusInWindow());
pane.setText("This issue is not reproducible in JDK 8 early-access build (8u172) which is yet to be released.");
node.setContent(pane);
obsList = FXCollections.observableArrayList();
for(int x = 0; x < 12; x++){
obsList.add(x);
}
listView.setItems(obsList);
node.setFocusTraversable(true);
node.requestFocus();
pane.requestFocus();
pane.grabFocus();
}
@FXML
private void removeItem(ActionEvent event) {
obsList.remove(0);
}
}
jeck猫
弑天下
相关分类