NetBeans (Java Swing): setting window size

It drives me crazy. When I set the appropriate size for my window in design mode, it simply ignores that size and uses something else when compiling and running. Even hard, I set the minimum size and preferred size, it just ignores it ... Why? How can I set my own size?

+7
java swing netbeans
source share
3 answers

Even if you set the size using minimumSize and preferredSize , you may have forgotten to call Window.pack() in which Swing will resize the components (and all its subcomponents) according to the set sizes.

You call this in your window (or something that creates your window) after all preferred sizes have been set.

Alternatively, you can use the Component.setSize() method, but it contains some caveats .

+6
source share

Did you check if you really set the size of the JFrame or contained JPanel?

Have you tried setSize ?

+1
source share

I found myself in a similar situation when I used netbeans ide. I read the following thread that helped:

http://forums.netbeans.org/ptopic28011.html

The swing application frame seems to save the size of the application window in a subfolder in your home directory (for Windows, the "Application Data" folder for Linux, in your home folder "~ /").

For example, for my application, "CrapApp" swing saved information about the size of the last window in the subfolder "~ / .CrapApp /" to a file called "mainFrame.session.xml".

So, no matter how I resized the window in the designer, when I start it seems to ignore it and instead load the window size from the settings inside this subfolder.

So, I decided to delete this subfolder with the saved settings, for example, in my case, "rm -rf ~ / .CrapApp /"

Then the problem disappeared, and I was able to resize in the designer and run the application with this size window now visible.

It made me want to find out what caused this problem. I noticed that just starting the application inside ide netbeans and closing it did not create a subfolder.

After a little use of my application, I noticed that the next action caused the generation of this subfolder ~ ~ .CrapApp /.

  • Going to my Help → About application
  • Click the Close button in the dialog box that appears.
  • Exit Application

And now the subfolder "~ / .CrapApp /" appears again. This help / dialog was automatically generated by netbeans ide, so I didn't really bother with it, but that seemed to be the culprit in my case.

Perhaps this may be a mistake in netbeans ide, I am using a somewhat old version (v6.8), which seems to be around the era of your original message, too.

0
source share

All Articles