Quijibo
Quijibo

Reputation: 333

Set the size of visible space in a JFrame

I have had this problem a few times before, and I finally attempted to solve it, but I cannot fond the right solution. I have a simple JFrame program. The basic JFrame code looks like this:

JFrame frame = new JFrame("halp");  
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(500,500);
    frame.setResizable(false);
    frame.setVisible(true);

Here's an image of what I'm trying to accomplish:

JFrame.

As you can see, there's space taken up by the top bar and the borders of the window. One way to fix this is to increase the size of the window, but that isn't neat at all, and also not every system has the same border sizes of the window.

I've done research and tried a few things I found on earlier asked questions:

I tried combining these methods, but nothing seemed to work.

What am I missing? Is there another aspect of the JFrame I need to add? Is it an incompatibility issue of BlueJ?

Upvotes: 2

Views: 291

Answers (1)

TT.
TT.

Reputation: 16146

frame.getContentPane().setPreferredSize(new Dimension(500,500));

followed by a

frame.pack();

should solve your problem.

Upvotes: 2

Related Questions