Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JInternalFrame

 
mitesh mehta
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having a simple application wherein a JFrame is having JPanel.I want to add an JInternalFrame within that JPanel.I would like to know whether is that possible?
I have tried with JDesktopPane but the JDesktopPane and the JInternalFrame are not visible.
Can anyone please help.
Thank you.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should place JInternalFrames in JDesktops... maybe if you posted the code you used we could help fix the problems you had with it?
 
mitesh mehta
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code is as follows :-
JPanel panel1 = new JPanel();
panel1.setVisible(true);
panel1.setBackground(Color.red);
JDesktopPane desk = new JDesktopPane();
desk.setBackground(Color.blue);
JInternalFrame frame = new JInternalFrame();
frame.setBounds(0,0,100,100);
frame.setVisible(true);
frame.show();
JInternalFrame frame1 = new JInternalFrame();
desk.add(frame1);
frame1.setLayer(new Integer(2));
frame1.setBounds(0,0,150,150);
frame1.setVisible(true);
frame1.show();
desk.add(frame);
desk.setVisible(true);
panel1.add(desk);
panel1.setVisible(true);
panel1.invalidate();
getContentPane().add(panel1);

///
When i ask for the desktopPane to return all the frames by the getAllFrames() i get the number of InternalFrames added to the desktopPane.But they are not visible.
Mitesh
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is that the JDesktopPane component does not have a preferred size... so when you add it to a JPanel (with default FlowLayout) it has size 0, and doesn't display. Either set BorderLayout on the JPanel and add the desktop to the center or call setPreferredSize() on the desktop.
 
mitesh mehta
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Nathan.
It worked.
Thanks a lot.
Mitesh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic