JavaFX 20:副屏主窗口打开的编辑窗口默认显示在主屏的解决方法
问题:JavaFX编辑窗口无法在主窗口所在副屏打开
我开发了一个小型JavaFX 20应用,主窗口基于FXML和CSS实现,包含一个列表,双击任意列表项会打开新窗口进行编辑。当前遇到的问题是:如果主窗口位于副屏,编辑窗口却会在主屏打开,而非主窗口所在的副屏。我曾尝试通过保存xProperty()和yProperty()的浮点值作为设置,以此在打开时定位第二个窗口,但该方法仅对主窗口有效,编辑窗口似乎被限制在主屏的坐标范围内。请问是否有办法获取主窗口所在的屏幕,并使用该屏幕的坐标而非主屏坐标来定位编辑窗口?另外,NetBeans运行在主屏,这或许是个线索(也可能不是)。
更新:尝试过的方法及代码片段
mainwindow.java
初始在主屏启动,但通过x和y坐标将其置于副屏:
public Window getOwner() { stage.getOwner(); } ... private void actionEntryEdit() { int sel_id; FXMLLoader editloader; DlgPopupEditController maincont = null; Parent editroot = null; Stage editstage = null; Scene editscene; if ( tblNotesView.getSelectionModel().getSelectedItem() != null ) { Note selnote = selModel.getSelectedItem(); sel_id = selnote.getID(); } else { sel_id = -1; } // we have selected a row so get it to the edit window if ( sel_id > 0 ) { editstage.toFront(); maincont.setNote(sel_id); editstage.show(); } }
dlgpopupedit.java
存储的设置应将其置于扩展副屏:
@Override public void initialize(URL url, ResourceBundle rb) { initLocalVars(); readSettings(); } ... public void setController(MainWindowController mwc) { MWC = mwc; stage.initOwner(MWC.getOwner()); } ... public void setScene(Scene sc) { displaySettings(); }
注:设置以浮点值形式从xProperty()和yProperty()获取,保存为Windows风格的.ini文件(使用Ini4J)。
内容的提问来源于stack exchange,提问作者AD5XJ
相关产品推荐
相关产品推荐

