I'm having difficulty determining the correct size of a JDesktopPane. The following code tells me that the size of the pane is 0 x 0
//Inside a JFrame
JDesktopPane myDesktop = new JDesktopPane();
this.setContentPane(myDesktop);
System.out.println(myDesktop.getSize());
However, after looking in the source for GridLayout.java, virtually identical code is used.
//Inside GridLayout.java, except I added the println() and omitted stuff
public void layoutContainer(Container parent) {
synchronized (parent.getTreeLock()) {
System.out.println(parent.getSize());
}
}
parent is the JDesktopPane that is being layed out.
The best I can figure is that somewhere in the innards of Swing/AWT the size of the JDesktopPane is being changed before getting passed to the LayoutManager. If I recall correctly, Java passes objects by reference. My next idea was that perhaps after applying the layout the size gets changed, so I tried the following:
//Inside the same JFrame
//After stuff that takes up space is added.
myDesktop.setLayout(new GridLayout(2,2));
System.out.println(myDesktop.getSize());
But no luck. As I understand it, this means, the somewhere a copy of the JDesktoPane is getting made, modified, and passed to the layout manager, but not original one.
Am I even remotely close? Can anybody tell me how I can access the actual size of the JDesktopPane?