简体   繁体   中英

JavaFX 2.0 how to “pin” a stage to another stage

So I have a JavaFX 2.0 application, and the main window is shown on startup. What I want to do is have the user press a button, and have another window pop up next to the main window.

So, I want an undecorated stage "pinned" to the left of the main stage.

I know how to make the window, and how to make it undecorated, the new window works fine, I just want to make it so that it stays in the same position relative to the main window (or stage, whichever you prefer to call it), when that window is moved.

Just set a listener to reposition your window when its 'buddy' window is repositioned or resized. There may be a lag, since sometimes those events don't get fired until the final new position/size is set, though.

A Stage has a heightProperty and widthProperty , to which you can bind a listener using:

stage.widthProperty().addListener(listener);

You can do the same with almost any property that's exposed - the position properties, etc.

Your listener needs to implement the ChangeListener<Number> interface.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM