gpt4 book ai didi

JavaFx 电子表格单元格右键单击打开对话框

转载 作者:行者123 更新时间:2023-11-29 04:40:07 27 4
gpt4 key购买 nike

我是 ControlsFx Api 的 SpreadSheet 功能的新手。我想在 Javafx 中右键单击 SpreadsheetViewSpreadsheetcell 打开 Dialog。非常感谢任何帮助。

最佳答案

这是您可以脱离标准 ContextMenu 并使用 Dialog 实现自己的处理程序的代码,在此示例中 TextInputDialog:

  SpreadsheetView spreadsheetView = new SpreadsheetView();
//off the standard ContextMenu
spreadsheetView.setContextMenu(null);
//set own handler for right click with Dialog
spreadsheetView.setOnContextMenuRequested(new EventHandler<ContextMenuEvent>() {
@Override public void handle(ContextMenuEvent event) {
CellView cellView = (CellView) event.getTarget();
TextInputDialog dialog = new TextInputDialog(cellView.getText());
Optional<String> result = dialog.showAndWait();
if (result.isPresent()){
System.out.println(cellView.getText());
}
}
});

我不太了解这个库,但它运行良好。工作原理示例:

enter image description here

我的程序:

public class MainController extends Application {

public static void main(String[] args) {
launch(args);
}

@Override public void start(Stage primaryStage) throws Exception {


SpreadsheetView spreadsheetView = new SpreadsheetView();
//off the standard ContextMenu
spreadsheetView.setContextMenu(null);
//set own handler for right click with Dialog
spreadsheetView.setOnContextMenuRequested(new EventHandler<ContextMenuEvent>() {
@Override public void handle(ContextMenuEvent event) {
CellView cellView = (CellView) event.getTarget();
TextInputDialog dialog = new TextInputDialog(cellView.getText());
Optional<String> result = dialog.showAndWait();
if (result.isPresent()) {
System.out.println(cellView.getText());
}
}
});

HBox hBox = new HBox();
hBox.getChildren().add(spreadsheetView);
Scene scene = new Scene(hBox);
primaryStage.setScene(scene);
primaryStage.show();
}
}

关于JavaFx 电子表格单元格右键单击打开对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39551268/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com