JavaFX and SwingNode - partial black Window

落爺英雄遲暮 提交于 2019-12-04 06:00:55

问题


I tried to use Swing Components in JavaFX with the SwingNode:

public class MyTest extends Application {

    @Override
    public void start(Stage stage) {

        final SwingNode swingNode = new SwingNode();
        FlowPane pane = new FlowPane();

        Button btn = new Button("1");
        btn.setVisible(false);
        pane.getChildren().add(btn);

        createAndSetSwingContent(swingNode);
        pane.getChildren().add(swingNode);


        stage.setScene(new Scene(pane, 100, 50));

        stage.show();

        btn.setVisible(true);

    }

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

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

After starting the application some parts of the window (the background and the JavaFX button) are black:

After a resize (or an other update) the window is shown correctly:

Why is it like this and how can I fix it?


回答1:


The Problem is an known bug in java 8 update 31.

(https://javafx-jira.kenai.com/browse/RT-37810)

It is fixed in java 8 update 40.




回答2:


objSwingNode.requestFocus(); objSwingNode.autosize();



来源:https://stackoverflow.com/questions/28175904/javafx-and-swingnode-partial-black-window

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