1
votes

Suppose I've done this -

SwingNode deviceView = new SwingNode();
JDesktopPane desktop = new JDesktopPane();
// Add elements to desktop
deviceView.setContent(desktop);

Is there a way remove desktop from deviceView? The best way I can come up with is -

deviceView.setContent(new JPanel());

But is there a way to simply remove it?


As noted in the comments I've tried deviceView.setContent(null); which appears to be bugged.

2
setContent(null) doesn't work? - James_D
@James_D nope, tried that first. - John C
I guess it is a bug in the Swing integration. The swing node is actually gets removed when using setContent(null) (you can try it with a JButton which is not clickable anymore) but the SwingNode does not get repainted somehow. - DVarga
@DVarga yes I've seen that in my attempts too. - John C

2 Answers

0
votes

You may try this out and let us know how it goes, although I have not tried it out.

deviceView.getContent().removeAll();
-1
votes

Late to the party but here is what you could try.
deviceView.getContent().removeAll(); /****Note : The UI may not show any updates even if you run it inside the SwingUtilities.invokeLater method */

/**** Now set a new instance that would allow you to set any other content later. At least that is what i have done in one of our Java FX App.*/
deviceView = new SwingNode();