2

My question is why when I press to the restore down (on a Windows platform) the JFrame is very tiny (see the bellow screenshot).

I use this code regarding State of the JFrame:

this.setExtendedState(View.MAXIMIZED_BOTH);

I need to use setMinimumSize()?

enter image description here

David Kroukamp
  • 36,155
  • 13
  • 81
  • 138

5 Answers5

3

Be sure that this.setExtendedState(JFrame.MAXIMIZED_BOTH) is executed AFTER setVisible(true). Also if you have a setResizable(false) call make sure it is executed AFTER the setExtendedState() one.

Mickäel A.
  • 9,012
  • 5
  • 54
  • 71
3

I think no one understood his question. He doesn't want to maximize it, he wants when he press "Restore Down", the window won't become so small. So what you need to do, "Restore Down" restores the window to its previous size before "Maximize" has been pressed.

So what I did was this

int Width = (int) java.awt.Toolkit.getDefaultToolkit().getScreenSize().getWidth();
int Height = (int) java.awt.Toolkit.getDefaultToolkit().getScreenSize().getHeight();
this.setSize(Width-100,Height-100);
this.setExtendedState(JFrame.MAXIMIZED_BOTH);

Therefore, every time you press Restore Down, the first time, the size will be the screen size - 100 pixels for width and height.

nhahtdh
  • 55,989
  • 15
  • 126
  • 162
2

What class is View?

If you are trying to set your JFrame size to maximum do this (notice I used the static variable available in JFrame class and not View):

JFrame frame=...;
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
David Kroukamp
  • 36,155
  • 13
  • 81
  • 138
0

As this was the first and most accurate question to my issue, I will add what I found here. I know it is 3 years old but my answer might help someone in the future. My issue was the same as above. When I built the Jframe I used:

frame.setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);

When I clicked the "restore down" button the window was really small and in the top left corner of the screen. I fixed this by calling:

frame.setBounds(100, 100, 450, 300);

After setVisible(true). Here is the code after my editing, the original code was created with Eclipse WindowBuilder. I am just editing it after. Here is the code complete:

public class MainWindow extends JFrame {

    private JPanel contentPane;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    MainWindow frame = new MainWindow();
                    frame.setVisible(true);
                    frame.setBounds(100, 100, 450, 300);
                    frame.setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public MainWindow() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
        //setBounds(100, 100, 450, 300);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        contentPane.setLayout(new BorderLayout(0, 0));
        setContentPane(contentPane);
    }

}

Basically what is happening (as far as I can determine) after the Jframe becomes visible it is first set to a size of 450x300, then immediately changes the size to maximized. Now when you hit the restore down button it will set it to the 450x300 size. I am currently searching for a way to override the method used to set the window size to the previous size (before hitting max), but I'm not at a point that I need to ask yet.

Dwayne B
  • 107
  • 1
  • 13
0
    appFrame = new JFrame("BufferedImage layers");
    Dimension asRestoredDown = new Dimension(400,400);//first time restored
    appFrame.setMinimumSize(asRestoredDown);
    appFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    appFrame.setExtendedState(appFrame.getExtendedState() | JFrame.MAXIMIZED_BOTH);
Tonecops
  • 127
  • 9