[英]Swing Content breaking in FX TabPane
I am working on a project that requires loading already existing complex Swing Content inside a UI built in FX.我正在开展一个项目,该项目需要在 FX 内置的 UI 中加载现有的复杂 Swing 内容。 The problem i get is, that the Swing Content constantly "breaks" leaving the corresponding Swing Node / FX Pane empty.我遇到的问题是,Swing 内容不断“中断”,使相应的 Swing 节点/FX 窗格为空。 I have built a minimal working code example to partly reproduce the problem.我已经构建了一个最小的工作代码示例来部分重现该问题。 When resizing the window containing 3 Tabs, the only Swing Node that shows properly is the one in the currently selected tab.调整包含 3 个选项卡的 window 大小时,唯一正确显示的 Swing 节点是当前选定选项卡中的节点。 Usually both other tabs "break".通常其他两个选项卡都“中断”。
public class Main extends Application {
private final SwingNode node1 = new SwingNode();
private final SwingNode node2 = new SwingNode();
private final SwingNode node3 = new SwingNode();
@Override
public void start(Stage primaryStage) {
try {
TabPane root = new TabPane();
Tab tab1 = new Tab("Tab 1");
Tab tab2 = new Tab("Tab 2");
Tab tab3 = new Tab("Tab 3");
createAndSetSwingContent();
tab1.setContent(node1);
tab2.setContent(node2);
tab3.setContent(node3);
root.getTabs().add(tab1);
root.getTabs().add(tab2);
root.getTabs().add(tab3);
Scene scene = new Scene(root, 400, 400);
primaryStage.setScene(scene);
primaryStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
private void createAndSetSwingContent() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JPanel panel1 = new JPanel(new BorderLayout());
JPanel panel2 = new JPanel(new BorderLayout());
JPanel panel3 = new JPanel(new BorderLayout());
JButton btn1 = new JButton("Button 1");
JButton btn2 = new JButton("Button 2");
JButton btn3 = new JButton("Button 3");
panel1.add(btn1);
panel2.add(btn2);
panel3.add(btn3);
node1.setContent(panel1);
node2.setContent(panel2);
node3.setContent(panel3);
}
});
}
public static void main(String[] args) {
launch(args);
}
}
Is this problem reproducable for anyone else?其他人是否可以重现此问题? And is this a java bug, or am i missing something in my code?这是一个 java 错误,还是我的代码中遗漏了什么? I am using Java 11 and JavaFX 11 in eclipse. I included the JavaFX11 jars as a User Library in the Classpath, and added the following VM Arguments in Run Configurations:我在 eclipse 中使用 Java 11 和 JavaFX 11。我将 JavaFX11 jars 作为用户库包含在类路径中,并在运行配置中添加了以下 VM Arguments:
--module-path "C:\JavaFX\javafx-sdk-11.0.2\lib" --add-modules javafx.controls,javafx.fxml,javafx.swing
Reminds me on an issue I had some years ago with JFXPanel - have you already tried Platform#setImplicitExit(false)?让我想起几年前我在使用 JFXPanel 时遇到的一个问题——您是否已经尝试过 Platform#setImplicitExit(false)?
Example:例子:
Platform.setImplicitExit(false);
Platform.runLater(new Runnable(){
public void run(){
createScene();
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.