简体   繁体   English

我可以将JInternalFrames添加到JPanel吗?

[英]Can I add JInternalFrames to a JPanel?

It seems that JInternalFrames can only be added to a JDesktopPane and you have to set your JFrame's content pane to that JDesktopPane. 看来JInternalFrames只能添加到JDesktopPane,并且您必须将JFrame的内容窗格设置为该JDesktopPane。 Something like: 就像是:

JFrame frame = new JFrame();
JDesktopPane desktopPane = new JDesktopPane();
JInternalFrame internalFrame = new JInternalFrame();

desktopPane.add(internalFrame);
frame.setContentPane(desktopPane);

The problem is that the JInternalFrames are allowed to move over anything that I add to the JFrame, like JPanels. 问题在于,允许JInternalFrames移动到我添加到JFrame的所有内容(如JPanels)上。

Is there a way for me to add the JInternalFrames/JDesktopPane to something else like a JPanel? 有没有办法将JInternalFrames / JDesktopPane添加到其他类似JPanel的东西? That way I can restrict the JInternalFrames to be within that JPanel. 这样,我可以将JInternalFrames限制在该JPanel中。 If that is not possible, then what other options do I have? 如果那不可能,那么我还有什么其他选择?

You can add any object to a JPanel that extends JComponent. 您可以将任何对象添加到扩展JComponent的JPanel中。 For example: 例如:

JFrame window = new JFrame();
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setBounds(30, 30, 300, 300);
window.setVisible(true);
window.setSize(600, 400);

JDesktopPane desktopPane = new JDesktopPane();
JInternalFrame internalFrame = new JInternalFrame();        
JPanel mainPanel = new JPanel();
mainPanel.add(desktopPane);
mainPanel.add(internalFrame);
window.add(mainPanel);

hope that helps! 希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM