Determining correct size of JDesktopPane

Reply

Join Date: May 2005
Posts: 3
Reputation: Postal Elf is an unknown quantity at this point 
Solved Threads: 0
Postal Elf Postal Elf is offline Offline
Newbie Poster

Determining correct size of JDesktopPane

 
0
  #1
May 28th, 2005
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?
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Determining correct size of JDesktopPane

 
0
  #2
May 28th, 2005
Are these JInternalFrames that your adding to the JDesktopPane?
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 3
Reputation: Postal Elf is an unknown quantity at this point 
Solved Threads: 0
Postal Elf Postal Elf is offline Offline
Newbie Poster

Re: Determining correct size of JDesktopPane

 
0
  #3
May 29th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Determining correct size of JDesktopPane

 
0
  #4
May 29th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 3
Reputation: Postal Elf is an unknown quantity at this point 
Solved Threads: 0
Postal Elf Postal Elf is offline Offline
Newbie Poster

Re: Determining correct size of JDesktopPane

 
0
  #5
May 29th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Determining correct size of JDesktopPane

 
0
  #6
May 31st, 2005
What about when you run the program, does nothing show up, or does the DesktopPane seem to have some size?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC