JavaFX和SwingNode - 部分黑色窗口 [英] JavaFX and SwingNode - partial black Window
本文介绍了JavaFX和SwingNode - 部分黑色窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试在SwingNode中使用JavaFX中的Swing组件:
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);
}
}
启动应用程序窗口的某些部分(背景和JavaFX按钮)是黑色的:
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:
< img src =https://i.stack.imgur.com/tP8Da.pngalt =在此处输入图像说明>
为什么会这样,我该如何解决?
Why is it like this and how can I fix it?
推荐答案
objSwingNode.requestFocus();
objSwingNode.autosize();
objSwingNode.requestFocus(); objSwingNode.autosize();
这篇关于JavaFX和SwingNode - 部分黑色窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文