The desktop - please help.

Hello,
I have a program as follows:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
* A class to test the JDesktopPane methods.
public class Test extends JFrame {
   private JDesktopPane desktop;
   public Test( ) {
      setTitle( "Desktop Test");
      setSize( 600, 400);
      setVisible( true);
      addWindowListener( new WindowAdapter( ) {
         public void windowClosing( WindowEvent e) {
            System.exit( 0);
      desktop = new JDesktopPane( );
      setContentPane( desktop);
      calculateSize( );
   public void calculateSize( ) {
      System.out.println( "Width is: " + desktop.getWidth( ));
      System.out.println( "Height is: " + desktop.getHeight( ));
      System.out.println( "Desktop is: " + desktop);
   public static void main( String[] args) {
      Test t = new Test( );
}Why are the getWidth() and getHeight() methods (of the JDesktopPane class) returning 0, and why is the line:
System.out.println( "Desktop is: " + desktop);returning the size of the desktop pane as 0x0. Since internalFrames can be added to this desktop at any location it must have some dimension (and not 0x0), so please can you help and show me how to obtain the the width and height of the desktop.
Thank you in advance.

OK what you need to do is add a "t.show()" command in the "main" method to show the frame, the frame hasn't been painted yet, so it has no dimension.

Similar Messages

Maybe you are looking for