在窗格中调整SwingNode的大小 [英] Resize SwingNode in Pane
问题描述
我是使用JavaFX的新手,我希望将一个JPanel添加到JavaFX窗格中。我目前的代码有效,但面板非常小。我希望能够调整它以适应JavaFX窗格。
I'm fairly new to using JavaFX and I am looking to add a JPanel into a JavaFX Pane. The code I currently have works, however the panel is very small. I want to be able to resize it so it fits the JavaFX pane.
代码:
// Add swing component to JFX
final SwingNode swingNode = new SwingNode();
createAndSetSwingContent(swingNode);
detailPane.getChildren().add(swingNode);
创建Swing内容方法:
Create Swing content method:
private void createAndSetSwingContent(final SwingNode swingNode) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
//Create the viewing pane.
dataComponentDetailPane = new JEditorPane();
dataComponentDetailPane.setEditable(false);
dataDetailView = new JScrollPane(dataComponentDetailPane);
// Create panel
mainSwingPanel = new JPanel();
mainSwingPanel.add(dataDetailView);
swingNode.setContent(mainSwingPanel);
}
});
}
如何使SwingNode / JPanel符合JavaFX窗格的大小?
How do I fit the SwingNode/JPanel to fit the size of the JavaFX pane ?
我正在使用FMXL创建Java FX窗格。提前致谢 !
I'm using FMXL to create the Java FX pane. Thanks in advance !
推荐答案
我遇到了与你相同的问题, Panel >之间存在问题
和 SwingNode
,我不确切知道为什么,但我还没有找到一起使用这个2的方式。
I had the same issue than you and there's really a problem between Panel
and SwingNode
, I don't know exactly why but I have not find the way of using this 2 together.
现在我有2个解决方案:
- 你可以阅读< a href =https://stackoverflow.com/questions/20350890/how-to-resize-swing-control-which-is-inside-swingnode-in-javafx8/23642899#23642899>这个如果你使用
group
调用:setAutosizeChildren(false)
就像解决方案一样。 - 你可以在不使用JPanel的情况下实现
SwingNode
,只需将它放在你拥有的JavaFX Pane
中,它就会自动适合。
- You can read this and if you use
group
call :setAutosizeChildren(false)
like said the solution. - You can implement the
SwingNode
without using the JPanel, just put it in theJavaFX Pane
you have, and it will automatically fits.
如果这不起作用,请发布可编辑的代码。
If this don't work, post a compilable code.
这篇关于在窗格中调整SwingNode的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!