Jump to content

How to set the size of a jframe in netbeans?

i have tried going to the properties of the jframe and changing it to my preferred size but it didnt work.i then typed this code and it didnt work either.is there any other way to do this.

 

 JFrame jframe = new JFrame();
    jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // set the jframe size and location, and make it visible
    jframe.setPreferredSize(new Dimension(400, 300));
    jframe.pack();
   

 

Link to comment
Share on other sites

Link to post
Share on other sites

here's an old function I had for making one, you can take bits and pieces of this if needed

 

Quote

public static JFrame makeWindow(int WIDTH, int HEIGHT, String NAME, Color COLOR) {
        JFrame game = new JFrame(NAME);
        game.setSize(WIDTH,HEIGHT);
        game.setMinimumSize(new Dimension(WIDTH,HEIGHT));
        game.setMaximumSize(new Dimension(WIDTH,HEIGHT));
        game.setResizable(false);
        game.setLocationRelativeTo(null);
        game.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        game.getContentPane().setBackground(COLOR);
        game.setLayout(null);
        return game;
    }

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×