Sandeep Bansal
Sandeep Bansal

Reputation: 6394

Size of JPanel isn't changing in Netbeans

I have a Netbeans GUI Project created with all the auto-generated content.

On the Main Form I have a Frame View > JPanel (mainPanel)

I have tried to change the preferredSize and MinimumSize to the Dimensions I wanted and also tried adding:

mainPanel.setSize(500,500);

mainPanel.setSize(new Dimension(500, 500));

But it doesn't change when I run the application. Can anyone help me out here.

Thanks.

Upvotes: 3

Views: 7207

Answers (2)

Costis Aivalis
Costis Aivalis

Reputation: 13728

Take also into consideration the size of your top-level container.

If you use Free Design layout i.e., then this code will change the size of your panel as soon as the second line runs, that applies to the JFrame hosting mainPanel:

    mainPanel.setPreferredSize(new Dimension(500, 500));
    setSize(new Dimension(1000, 1000));

Designing GUI's by hand is a great activity. It is especially beneficiary during the Swing learning phase, or in order to create some special interface. For mainstream application development though, like multiple forms for some CRUD, or like business applications of most types that use highly repetitive software patterns it pays off big time to use a graphical designer like Matisse. Saves you a lot of time and money. You can also prototype your application quickly and agree upon the design with your customer.

Upvotes: 3

ICas
ICas

Reputation: 197

Have you tried updating the component after manually setting the size? Try a repaint() on frame.

Other component commands are available at http://download.oracle.com/javase/6/docs/api/java/awt/Component.html

Upvotes: 1

Related Questions