javafx SwingNode not working until window is resized

落爺英雄遲暮 提交于 2019-12-12 11:18:46

问题


I have been trying the SwingNode from JavaFX8 using this code. The problem is when the window appears I can not click the button, until I have resized the window. Moving it does not work. I need to either maximize it or resize it with the mouse to get the button to respond.

I realize this could be a bug given that javafx8 is still in beta, but if thats not the case is there something I need to do to make this work with out resizing the window first?

    public class SwingNodeTest extends Application {

    private SwingNode swingNode;

    @Override
    public void start(Stage stage) {
        swingNode = new SwingNode();    
        createAndSetSwingContent();    
        StackPane pane = new StackPane();
        pane.getChildren().add(swingNode);    
        stage.setScene(new Scene(pane, 100, 50));
        stage.show();
    }

    private void createAndSetSwingContent() {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                swingNode.setContent(new JButton("Click me!"));
            }
        });
    }

    public static void main(String[] args) {
        Application.launch(args);           
    }
}

回答1:


Your code is simplistic, so it is most likely a bug in the beta.



来源:https://stackoverflow.com/questions/17737266/javafx-swingnode-not-working-until-window-is-resized

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!