Layout bug with SwingNode ?
Kevin Rushforth
kevin.rushforth at oracle.com
Fri Feb 23 13:42:50 UTC 2018
This does sound like a bug. Can you file it at http://bugreport.java.com/ ?
One possible workaround might be to set the size of the scene when you
first create it:
new Scene(root, WIDTH, HEIGHT)
-- Kevin
Adam Granger wrote:
> Greeting,
>
> (https://stackoverflow.com/questions/48937412/node-snapshot-causing-layout-issue)
>
> Using JavaFX 9.0.4 I'm embedding some 3rd party Swing content in a
> JavaFX app. The 3rd party content already has its own preferred size,
> so I'm wrapping it with a StackPane to stretch it out...
>
> However, when node.snapshot() is called this causes the SwingNode to
> jump back to its preferred size, manually resizing the window causes
> it to fill the window again.
>
> I've also identified this only occurs if the scene is first shown
> without content and the content is added later.
>
> Is this a bug? How can I work around it?
>
> The following example recreates the issue
>
> public
>
> class
>
> NodeSnapshotFunny
>
> extends
>
> Application
>
> {
>
> @Override
>
> public
>
> void
> start
> (
> Stage
> stage
> )
>
> throws
>
> Exception
>
> {
>
> SwingNode
> swingNode
> =
>
> new
>
> SwingNode
> ();
>
> Button
> button
> =
>
> new
>
> Button
> (
> "Test"
> );
>
> button
> .
> setOnAction
> (
> event
> ->
>
> {
>
> WritableImage
> image
> =
> button
> .
> snapshot
> (
> null
> ,
>
> null
> );
>
> });
>
> StackPane
> stackPane
> =
>
> new
>
> StackPane
> (
> swingNode
> );
>
> Scene
> scene
> =
>
> new
>
> Scene
> (
> stackPane
> );
>
> stage
> .
> setScene
> (
> scene
> );
>
> stage
> .
> show
> ();
>
> stackPane
> .
> getChildren
> ().
> add
> (
> button
> );
>
> SwingUtilities
> .
> invokeLater
> (()
>
> ->
>
> {
>
> JPanel
> jPanel
> =
>
> new
>
> JPanel
> ();
>
> jPanel
> .
> setPreferredSize
> (
> new
>
> Dimension
> (
> 300
> ,
>
> 300
> ));
>
> jPanel
> .
> setBackground
> (
> Color
> .
> red
> );
>
> swingNode
> .
> setContent
> (
> jPanel
> );
>
> });
>
> }
>
> public
>
> static
>
> void
> main
> (
> String
> []
> args
> )
>
> {
>
> launch
> (
> args
> );
>
> }
>
> }
>
>
>
More information about the openjfx-dev
mailing list