Reputation: 13061
i'm developing a java application with a main Panel in which i add a JDesktopPane
.
users clicking on JButton
, will show a JInternalFrame
. My problem is that if i use Mac OSx look and feel, the JDesktopPane
shows with correct size the JInternalFrame
, if i use other look and feel, it will display JInternalFrame
in the dimension of screen. This is what i do:
In main JPanel
:
jDesktopPane1 = new JDesktopPane();
setContentPane(jDesktopPane1);
when users click JButton(s)
:
public void addInDesktop(JInternalFrame frame){
frame.setVisible(true);
try {
jDesktopPane1.setSize(frame.getSize());
jDesktopPane1.setPreferredSize((frame.getSize()));
System.out.println(frame.getSize().toString());
System.out.println(jDesktopPane1.getSize().toString());
jDesktopPane1.add(frame);
frame.moveToFront();
frame.setSelected(true);
} catch (PropertyVetoException e) {
e.printStackTrace();
}
}
The System.out.println
says me that the dimension of JDesktopPane and JInternalFrame is the same, but why it show me the JInternalFrame in full screen size?
Upvotes: 0
Views: 4004
Reputation: 11
If you want to set the size as wide and high as your jframe where you are going to put in. You can use
variable_desktopPane.setBounds(this.getBounds());
By this
I mean the Jframe you are calling its bounds.
I hope this helps, greetings.
Upvotes: 1
Reputation: 2196
If you were to print out the sizes after jDesktopPane1.add(frame) you would then probably see the change in size. I would suggest that setting the desktop pane to the size of the internal frame is a bad practice - I would have thought it should remain the size of the client area of the parent JFrame the desktop pane sits in (the frame where you call setContentPane(jDesktopPane1) ), and just let the internal frame sit somewhere within it naturally.
What might be happening is that setting the pane and internal to the same size might make the look and feel assume you mean 'maximized', and so when it resolves the size of the desktop pane correctly it does something weird with the internal frame.
Try not calling setSize() / setPreferredSize() on the desktop pane and see if it then behaves consistently across L&Fs. Perhaps then you can figure out what best to do with the internal frame if its default size isn't what you want.
Upvotes: 2