Search code examples
javaswingnetbeansdesigner

Netbeans designer shows different form than when the program runs


In netbeans designer it looks like this:

When I run the application it looks like this:

I am using cardLayout as main layout and cards use free design layout, there are multile cards but all of them are the same size like the first screenshot.


Solution

  • This is because of Nimbus look and feel is default for swing application.

    For reference link to Oracle docs. https://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/index.html

    The "look" of an application refers to its appearance. The "feel" refers to how the widgets behave.

    Editing here since I don't have enough reputation to add a comment.

    Refer: NetBeans (Java Swing): Set window size

    Accepted Answer:

    Even if you've set the size with minimumSize and preferredSize, you might have forgotten to call Window.pack() in which Swing will resize the components (and all of it's subcomponents) according to the sizes set.

    You call it in your window (or whatever is building your window) after all the preferred sizes are set.