| | |
Determining correct size of JDesktopPane
![]() |
•
•
Join Date: May 2005
Posts: 3
Reputation:
Solved Threads: 0
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?
//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?
•
•
Join Date: May 2005
Posts: 3
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by server_crash
Are these JInternalFrames that your adding to the JDesktopPane?
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
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.
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.
•
•
Join Date: May 2005
Posts: 3
Reputation:
Solved Threads: 0
•
•
•
•
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.
![]() |
Similar Threads
- CD Burning Error: Block size does not correspond to image length (Windows NT / 2000 / XP)
- My computer randomly restarts (Windows NT / 2000 / XP)
- Unable to get Hard drive to boot ???? (Storage)
- Monitor has the jiggles... (Monitors, Displays and Video Cards)
Other Threads in the Java Forum
- Previous Thread: How to position buttons/boxes in a JTabbed Pane?
- Next Thread: Another "cannot find symbol" compiling error
| Thread Tools | Search this Thread |
-xlint android api applet application array arrays automation bi binary blackberry block bluetooth chat class client code compile compiler component database developmenthelp eclipse error event fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide image int integer j2me j2seprojects java javac javaprojects jetbrains jni jpanel jtable julia learningresources lego linux list login loops mac main map method methods mobile myregfun netbeans newbie nonstatic notdisplaying number online pearl problem program programming project qt recursion scanner screen server set singleton sms sort spamblocker sql string swing system textfields thread threads time title tree tutorial-sample update variablebinding windows working xor






