0

I am working on a Swing application that starts with JFrame, but all the other frames are included as JInternalFrames, and i am facing some serious screen size problems when i instaled it in different computers, i used the following methode to set the JFrame in full screen

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setBounds(0, 0, screenSize.width, screenSize.height);
    JFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);

But I observe no difference. I also want to adjust the JInternalFrames with the screen size. If you have any suggestions or solutions, please help

Sujay
  • 6,753
  • 2
  • 30
  • 49
Zakaria Marrah
  • 755
  • 6
  • 15
  • 28
  • 1
    Are you adding internal frames to a [`JDesktopPane`](http://docs.oracle.com/javase/tutorial/uiswing/components/internalframe.html)? What platform(s)? Please edit your question to include an [sscce](http://sscce.org/) that shows the particular problem you have encountered. – trashgod Sep 20 '12 at 15:45
  • Yes, i add the JInternalFrame to the JDesktopPane , what i want is to make JINternalFrames flexible with the size of any screen. – Zakaria Marrah Sep 21 '12 at 10:36

1 Answers1

3

You should set the frame extended state like this:

frame.setExtendedState(frame.getExtendedState() | JFrame.MAXIMIZED_BOTH);

You're going to need a component listener to listen for the frame expanding to fit the screen and for resize changes.

    frame.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent event) {
            Dimension d = frame.getContentPane().getSize();
            // code to save frame size or calculate internal frame sizes
            frame.validate();
        }
    });
Gilbert Le Blanc
  • 50,182
  • 6
  • 67
  • 111