Hi Kevin, Thanks for the quick feedback. I did go ahead and file one last week:
JDK-8154846 : SwingNode does not resize when content size constraints are changed (http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8154846) Looking forward to the fix! Thanks, BB -----Original Message----- From: Kevin Rushforth [mailto:kevin.rushfo...@oracle.com] Sent: Thursday, April 28, 2016 1:13 PM To: Brian Bolstad Cc: Stijn Debruyckere; openjfx-dev@openjdk.java.net Subject: Re: SwingNode doesn't respond to Swing component resize? Yes, this seems like a bug to me, too. Can you please file a bug? You can find instructions for filing a bug here: https://wiki.openjdk.java.net/display/OpenJFX/Submitting+a+Bug+Report The page for filing a bug is here: http://bugreport.java.com/bugreport/ -- Kevin Brian Bolstad wrote: > Thanks for the response, Stijn. > > Even without setting the size directly and with the revalidate call, I am > still unable to get the SwingNode to resize. The problem to me seems to be > that a SwingNode caches the size constraints of its Swing component, but > those caches don’t get refreshed when the size constraints of the Swing > component are changed, even when a layout pass is performed. There are > listeners for the size constraint properties (down in JLightweightFrame), but > as nearly as I can tell, these only get called when you first set the > content, or when a component is added or removed from the LW frame. > > I’ve found that if I explicitly call SwingNode.setContent(component) each > time I update the size constraints of component, then the SwingNode will > resize, but that is wasteful (destroys and recreates the LW frame) and > shouldn’t be necessary. > > There may be a concept that I’m completely missing here, but this feels like > a bug with SwingNode. > > Thanks, > BB > > From: Stijn Debruyckere [mailto:stijn.debruyck...@luciad.com] > Sent: Friday, April 22, 2016 9:56 AM > To: Brian Bolstad > Cc: openjfx-dev@openjdk.java.net > Subject: Re: SwingNode doesn't respond to Swing component resize? > > You should call component.revalidate() after changing it's preferred size I > believe (didn't check your program though). > > If that doesn't help, you could check if you maybe tampered with the Direct3D > settings: > > // Verify that Direct3D is enabled (the default setting), to avoid resize > issues. > > if ( Boolean.valueOf(System.getProperty("sun.java2d.noddraw", > "false")) || > > !Boolean.valueOf(System.getProperty("sun.java2d.d3d", "true")) ) > { > > throw new IllegalStateException("Do not change the Direct3D default > settings (Windows specific), " > > + "it may cause glitches during > frame re-sizing."); > > } > > Note: you shouldn't call setSize directly on Swing components, layout > managers should take care of that. > > Kind regards, > Stijn > > ________________________________ > From: "Brian Bolstad" > <bbols...@ikonscience.com<mailto:bbols...@ikonscience.com>> > To: openjfx-dev@openjdk.java.net<mailto:openjfx-dev@openjdk.java.net> > Sent: Monday, April 18, 2016 10:08:10 PM > Subject: SwingNode doesn't respond to Swing component resize? > > Hello everyone, > > In the SwingNode#resize(double, double) documentation, it states: > > "Applications should not invoke this method directly. If an application needs > to directly set the size of the SwingNode, it should set the Swing > component's minimum/preferred/maximum size constraints which will be > propagated correspondingly to the SwingNode and it's parent will honor those > settings during layout." > > However, I'm not seeing this behavior-the SwingNode doesn't resize for me > unless I remove and re-add the Swing component to the SwingNode after > resizing. > > In the implementation, the private class SwingNodeContent has methods like > preferredSizeChanged that I assume should be called when the Swing component > size constraints are modified. However, it looks to me like > JLightweightFrame only installs pref/max/min size property change listeners > on components added after the first one. So, SwingNode never gets notified > of the size changes and never updates it's cached values for the swing > component's sizes and never updates its layoutBounds. > > Below is a sample that demonstrates the problem I'm seeing; if you click the > button, it will double its size, but the enclosing SwingNode doesn't change > size. I'm running JavaFX 8u66 on Windows 10. > > I'm very new to JavaFX, so what am I doing wrong? > > Thanks, > BB > > import javafx.application.Application; import > javafx.embed.swing.SwingNode; import javafx.scene.Scene; import > javafx.scene.layout.StackPane; import javafx.scene.paint.Color; import > javafx.scene.shape.Rectangle; import javafx.stage.Stage; > > import javax.swing.*; > import java.awt.*; > > public class SwingNodeResize extends Application { > @Override > public void start(Stage primaryStage) > { > SwingNode swingNode = new SwingNode(); > > init(swingNode); > > StackPane root = new StackPane(new Rectangle(500, 500, Color.RED), > swingNode); > Scene scene = new Scene(root); > > primaryStage.setTitle("SwingNode Resize"); > primaryStage.setScene(scene); > primaryStage.show(); > } > > private void init(final SwingNode node) > { > SwingUtilities.invokeLater(() -> > { > JButton button = new JButton("Click me!"); > button.addActionListener(event -> > { > Dimension buttonSize = button.getSize(); > buttonSize.setSize(buttonSize.getWidth() * 2, > buttonSize.getHeight() * 2); > > button.setPreferredSize(buttonSize); > button.setMinimumSize(buttonSize); > button.setMaximumSize(buttonSize); > button.setSize(buttonSize); > > System.out.println("Button size: " + > button.getPreferredSize() + "; " + > "SwingNode size: " + new Dimension((int) > node.prefWidth(-1), (int) node.prefHeight(-1))); > }); > > node.setContent(button); > }); > } > > public static void main(String[] args) > { > launch(args); > } > } > >