0

It seems that JInternalFrames can only be added to a JDesktopPane and you have to set your JFrame’s content pane to that 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.

Is there a way for me to add the JInternalFrames/JDesktopPane to something else like a JPanel? That way I can restrict the JInternalFrames to be within that JPanel. If that is not possible, then what other options do I have?

Alan
  • 175
  • 4
  • 15
  • 1
    JDesktopPane is a JComponent. AFAIK, you can add it to a JFrame or a JPanel as any other JComponent. I didn't see anything in the documentation that says that JDesktopPane must be set as the content pane of a JFrame. – JB Nizet Oct 04 '14 at 16:18
  • You can try solutions from this link: http://www.coderanch.com/t/342586/GUI/java/JinternalFrame-moveable – Alexey Semenyuk Oct 04 '14 at 16:26
  • Or this [example](http://stackoverflow.com/a/4091329/230513). – trashgod Oct 04 '14 at 16:37

1 Answers1

1

You can add any object to a JPanel that extends JComponent. 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!

alex436
  • 120
  • 8