Tony Ogrewall
Tony Ogrewall

Reputation: 471

How to maximize a JFrame through code?

How to maximize a JFrame through code?

Upvotes: 46

Views: 64034

Answers (5)

Jan S
Jan S

Reputation: 117

for similar problems with: https://bugs.java.com/bugdatabase/view_bug?bug_id=7177173

An issue on jdk7. Try to call .setExtendedState() not directly after .setVisable()

Upvotes: 1

Swartblits
Swartblits

Reputation: 51

Yea the Toolkit solution ignores the windows task bar and uses the full screen which is not what you want.

For an immediate maximise of your form just add this in the JFrame constructor after the InitiateComponents() call.

this.setExtendedState(JFrame.MAXIMIZED_BOTH);

The class extends JFrame of course:

public class MyForm extends javax.swing.JFrame

Upvotes: 5

ArchuSu
ArchuSu

Reputation: 31

setExtendedState(JFrame.MAXIMIZED_BOTH); is not working is java 7

You can try this code it works.

     Toolkit tk = Toolkit.getDefaultToolkit();  
     int xSize = ((int) tk.getScreenSize().getWidth());  
     int ySize = ((int) tk.getScreenSize().getHeight());  
     setSize(xSize,ySize);

Upvotes: 3

user2028750
user2028750

Reputation:

this works perfectly till java 7

public class TEST
{
    public static void main(String args[])
    {
        JFrame jf= new JFrame();
        jf.setVisible(true);
        jf.setExtendedState(JFrame.MAXIMIZED_BOTH);
        }
}

Upvotes: 8

Harry Joy
Harry Joy

Reputation: 59694

Try this:

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

Upvotes: 79

Related Questions