我是新來的SpreadSheet功能ControlsFx Api。我想打開Dialog
在Javafx的SpreadsheetView
的Spreadsheetcell
的右鍵點擊。任何幫助是極大的讚賞。JavaFx電子表格單元格右鍵單擊打開對話框
回答
這是代碼,你可以關閉標準的文本菜單和工具自己的處理程序與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());
}
}
});
我不知道很好這個庫,但它的作品好。 實例它的工作原理:
我的程序:
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();
}
}
感謝您的努力,但不知何故,它不適合我,你能否粘貼你的整個程序。 – DeepInJava
我添加了我的程序 – BadVegan
現在它適用於我。我的項目當時沒有正確構建。抱歉! – DeepInJava
它使用上點擊鼠標時,檢查表視圖並點擊它的鼠標處理火災FX新的對話然後接受輸入並更新fx表視圖。
table.setOnMousePressed(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
if (event.getClickCount() == 1) {
Call dialogue method of java fx
}
}
});
或者如果你想請右鍵單擊您可以創建細胞
如
FirstNameCol.setCellFactory(new Callback<TableColumn<Person, String>, TableCell<Person, String>>() {
@Override
public TableCell<Person, String> call(TableColumn<Person, String> col) {
final TableCell<Person, String> cell = new TableCell<>();
cell.textProperty().bind(cell.itemProperty()); // in general might need to subclass TableCell and override updateItem(...) here
cell.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
if (event.getButton == MouseButton.SECONDARY) {
// handle right click on cell...
// access cell data with cell.getItem();
// access row data with (Person)cell.getTableRow().getItem();
}
}
});
return cell ;
}
});
- 1. 從表格單元格按鈕打開對話框
- 2. 雙擊DataGridView單元格打開表單
- 3. 如何在電子表格中打開XML電子表格「uncollapse」單元格?
- 4. 允許單擊鼠標左鍵單擊鼠標右鍵或按Ctrl鍵單擊打開對話框
- 5. 打開模式對話框從內部表格單元
- 6. 打開xml sdk電子表格檢查合併的單元格
- 7. 當用戶點擊Google電子表格單元格時如何顯示錶單或對話框
- 8. 單擊單元格時彈出延遲打開彈出式對話框
- 9. 右對齊表格單元格位置
- 10. 在JavaFX中右鍵單擊?
- 11. 防止從右鍵單擊樹視圖單元格選擇樹單元格
- 12. Google電子表格單元格引用合併單元格
- 13. 在jqGrid中打開單元格中的模式對話框
- 14. 如何右鍵單擊Java JList的單元格,然後像左鍵單擊一樣選擇該單元格?
- 15. GWT電子表格單元格
- 16. 單擊按鈕時打開對話框。
- 17. jQuery對話框不能單擊打開
- 18. 右鍵單擊datagrid單元格以彈出複製菜單(ContextMenu)
- 19. 點擊表格視圖單元格打開地圖與路線
- 20. 打開表格視圖單元格的URL點擊
- 21. C#DataGridView右鍵單擊上下文菜單單擊檢索單元格值
- 22. 打開電子表格
- 23. 表格單元右對齊行內
- 24. Jtable中單元格的行爲(單擊鼠標右鍵)
- 25. 將Google電子表格單元格摺疊爲單個單元格
- 26. 合併單元格的CF電子表格邊框
- 27. C#打開Xml SDK 2.0電子表格設置單元日期時間格式
- 28. Google電子表格使用腳本打開最後編輯的單元格
- 29. JavaFx DatePicker單色單元格
- 30. 在UserForm打開時單擊單元格時填充TextBox與單元格引用
你好,你要直接顯示對話框後點擊右鍵? – BadVegan
@BadVegan,是的,我想單擊鼠標右鍵後直接顯示對話框。 – DeepInJava