943,986 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 4307
  • Java RSS
May 28th, 2005
0

Determining correct size of JDesktopPane

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Postal Elf is offline Offline
3 posts
since May 2005
May 28th, 2005
0

Re: Determining correct size of JDesktopPane

Are these JInternalFrames that your adding to the JDesktopPane?
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
May 29th, 2005
0

Re: Determining correct size of JDesktopPane

Quote originally posted by server_crash ...
Are these JInternalFrames that your adding to the JDesktopPane?
Yes. My appologies for the confusion. I have a JFrame object with a JDesktopPane. I'm trying to add 4 JInternalFrames for the 3 axes of a 3D scene, plus one camera frame. I need to know the size of the JDesktopPane so I can set the initial size of the JInternalFrames to fill the screen. After that it doesn't matter, because I want the user to be able to move the JInternalFrames at will. Using GridLayout does not behave appropriately, because although it gets the initial positions right, when I try to drag one of the JInternalFrames, the other two reajust themselves in the GridLayout.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Postal Elf is offline Offline
3 posts
since May 2005
May 29th, 2005
0

Re: Determining correct size of JDesktopPane

You have to set the size of the JInternalFrames before you add them to the JDesktopPane. If you don't, then you will get 0 size for the JDesktopPane and it wont show up.
I wouldn't worrry about the size of the JDesktopPane. Why don't you try not setting the size of the JDesktopPane and see if it will resize automatically to the sizes of the JInternalFrames.
Also, all layout managers will resize or reposition the components when somethings changed. You could try to set the layout manager to null and use the setbounds() method to set the position of the frames, but I don't know how that will work.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
May 29th, 2005
0

Re: Determining correct size of JDesktopPane

Quote originally posted by server_crash ...
You have to set the size of the JInternalFrames before you add them to the JDesktopPane. If you don't, then you will get 0 size for the JDesktopPane and it wont show up.
I wouldn't worrry about the size of the JDesktopPane. Why don't you try not setting the size of the JDesktopPane and see if it will resize automatically to the sizes of the JInternalFrames.
Also, all layout managers will resize or reposition the components when somethings changed. You could try to set the layout manager to null and use the setbounds() method to set the position of the frames, but I don't know how that will work.
Even when I set the size of the JInternalFrames, the JDesktopPane still seems to think it has a 0x0 size. When I apply a GridLayout to the JDesktopPane it thinks it has a 0x0 size too. That last part is exactly what I'm trying to do, but I don't know what values to use because I don't know the size of the JDesktopPane.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Postal Elf is offline Offline
3 posts
since May 2005
May 31st, 2005
0

Re: Determining correct size of JDesktopPane

What about when you run the program, does nothing show up, or does the DesktopPane seem to have some size?
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: How to position buttons/boxes in a JTabbed Pane?
Next Thread in Java Forum Timeline: Programmer needed (Paid)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC