Zakaria Marrah
Zakaria Marrah

Reputation: 765

how to adjust JFrame and JInternal frames with any screen size?

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

Upvotes: 0

Views: 2329

Answers (1)

Gilbert Le Blanc
Gilbert Le Blanc

Reputation: 51565

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();
        }
    });

Upvotes: 3

Related Questions