[英]JavaFx embed Swing JDesktopPane doesn't display anything
I have read and ran with success this tutorial . 我已阅读并成功运行了本教程 。
I want to embed internal frames into JavaFX using Swing JDesktopPane . 我想使用Swing JDesktopPane将内部框架嵌入到JavaFX中。
Code: 码:
public class FxSwingFx extends Application {
private static void createSwing( SwingNode swingNode ) {
final JDesktopPane desktopPane = new JDesktopPane();
swingNode.setContent( desktopPane );
final JInternalFrame if1 = new JInternalFrame( "Hello, ", true, true, true, true );
final JInternalFrame if2 = new JInternalFrame( " World!", true, true, true, true );
if1 .setVisible( true );
if2 .setVisible( true );
desktopPane.setVisible( true );
desktopPane.add( if1 );
desktopPane.add( if2 );
}
@Override
public void start( Stage primaryStage ) throws Exception {
final SwingNode swingNode = new SwingNode();
final BorderPane root = new BorderPane( swingNode );
root.setBottom( new Button( "FX Button" ));
SwingUtilities.invokeLater(() -> createSwing( swingNode ));
primaryStage.setScene( new Scene( root, 400, 300 ));
primaryStage.show();
}
public static void main( String[] args ) {
launch( args );
}
}
Result: 结果:
Question : Why internal frames aren't shown? 问题 :为什么不显示内部框架?
The condition to see internal frames are: 查看内部框架的条件是:
setSize()
, setPreferredSize()
isn't enougth setSize()
设置大小, setPreferredSize()
不明确 setVisible( true )
must have been called setVisible( true )
必须已被调用 Code: 码:
public class FxSwingFx extends Application {
JInternalFrame createInternalFrame( String title, int width, int height ) {
final JInternalFrame frame = new JInternalFrame( title, true, true, true, true );
frame.setVisible( true );
frame.setSize( width, height );
return frame;
}
void createSwing( SwingNode swingNode ) {
final JDesktopPane desktopPane = new JDesktopPane();
desktopPane.add( createInternalFrame( "One", 400, 300 ));
desktopPane.add( createInternalFrame( "Two", 400, 300 ));
swingNode.setContent( desktopPane );
}
@Override
public void start( Stage primaryStage ) throws Exception {
final SwingNode swingNode = new SwingNode();
SwingUtilities.invokeLater(() -> createSwing( swingNode ));
final BorderPane root = new BorderPane( swingNode );
final Button jfxBtn = new Button( "FX Button" );
root.setBottom( jfxBtn );
primaryStage.setScene( new Scene( root, 600, 500 ));
primaryStage.show();
}
public static void main( String[] args ) {
launch( args );
}
}
Result: 结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.