0

I'm building an app with Netbeans GUI Builder, and I want the main JFrame to be maximised, so have set:

setExtendedState(JFrame.MAXIMIZED_BOTH);

However, Netbeans calls pack() which results in the JFrame size being reduced. I know I can use the above code again after pack() has been called, but is there anyway I can prevent Netbeans from inserting the pack() line so I can keep my code a bit cleaner?

(Netbeans puts its pack() line in a block that you can't edit, so I can't simply remove it in the usual manner.)

mKorbel
  • 109,525
  • 20
  • 134
  • 319
ban-geoengineering
  • 18,324
  • 27
  • 171
  • 253
  • 5
    Given `pack()` ***should*** be called at some stage in the creation of the GUI, you should really be looking at a way to re-order the invocation of the methods, rather than get the JRE to not call `pack()`. – Andrew Thompson Mar 07 '13 at 12:14
  • there is issue with sizing came from built_in GroupLayout, don't to use XxxBuider – mKorbel Mar 07 '13 at 12:23
  • Thanks Andrew. I've just stuck with my original which was just to call setExtendedState(JFrame.MAXIMIZED_BOTH); after the call to NB's initComponents() method (which included the call to pack()). – ban-geoengineering Apr 08 '14 at 16:55

3 Answers3

2

Go to "Design" of your JFrame, click on JFrame fmor the Navigator window, then on "Code" in Properties tab click on

Form Size Policy -> No Resize Code

That should do it.

Panayotis
  • 1,792
  • 23
  • 32
  • Thanks for this. This was the kind of answer I was looking for, but when I do what you suggested and run the app, then click the JFrame window's "Restore Down" icon, the window disappears... re Andrew Thompson comment, above. – ban-geoengineering Apr 08 '14 at 16:46
  • What is the "restore down" icon? – Panayotis Apr 09 '14 at 17:50
  • At the top right hand corner of each window on Windows, you have three icons - "Minimize", "Restore Down" and "Close". Restore Down normally reduces the size of the window, but in the case I was reporting, it reduced the size down to zero. :( – ban-geoengineering Apr 14 '14 at 09:37
  • Probably you need to define the minimum/recommended size of the frame ? – Panayotis Apr 26 '14 at 08:16
1

It may be possible to coerce the GUI designer to do what you want. As an alternative, manage your own top-level container, Main.JFrame in this example, and use the designer to manage individual panels.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
-2

Probably something with layouts would be better. But my solution: override Window.pack :)

@Override
public void pack() {
}
Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
  • 1
    That's a poor 'solution' that will cause two problems for every one it supposedly solves. – Andrew Thompson Mar 07 '13 at 12:13
  • @AndrewThompson thoughtless of ne, appreciated. – Joop Eggen Mar 07 '13 at 12:16
  • @Joop Eggen agreed with (@Andrew Thompson), not with downvoter, sure/but this is specific issue with GroupLayout, there isn't any chance to re_layout this container, see my [4th. point](http://stackoverflow.com/a/15144915/714968), btw I saw that there a few times – mKorbel Mar 07 '13 at 12:56