I have a small javafx 20 app that displays a main window (FXML with CSS) which contains a list. A double click of any row will open a new window to edit that row.
The problem is that, if the main window is on a secondary screen, the edit window opens on the primary screen and not the secondary screen where the main window is open.
I have tried to use the xProperty() and yProperty() double values, saved as settings, to position the second window on open, but that only worked on the main window. The edit window seems confined to the values of the primary screen.
Is there a way to get the screen that opened it and use the x and y of that screen rather than the primary screen.
BTW NetBeans runs in the primary screen. That may be a clue...maybe not.
UPDATE
OK, so I have tried a number of things including those suggested below. Here are some snippets from the current state of the app:
mainwindow.java is started on the primary screen but x and y place it on the secondary screen.
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 where stored settings should place it on the extended second screen:
@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();
}
Note: settings are saved in Windows style .ini file (using Ini4J) as double from the xProperty() and yProperty() double values.