While I was debugging earlier, I discovered something a little strange. With the following code, the width of the JDesktopPane
changes, seemingly without any interaction, directly or indirectly.
import javax.swing.*;
public class Main
{
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.setSize(960, 640);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.setLocationRelativeTo(null);
JDesktopPane desktop = new JDesktopPane();
frame.add(desktop);
System.out.println(desktop.getWidth()); // 0
frame.setVisible(true);
System.out.println(desktop.getWidth()); // ~1/2 monitor width
new JInternalFrame();
System.out.println(desktop.getWidth()); // monitor width
}
}
I can understand why the width would change when the JFrame
is changed, but why does it change simply because a JInternalFrame
is created?