set JPanel size

How can i set the JPanel size?

Can i use setPreferredSize(100,100);?

thanks
KennywenAsked:
Who is Participating?
 
mmuruganandamConnect With a Mentor Commented:

controlMessage.setPreferredSize(new Dimension(100,100));

This will work.
0
 
mmuruganandamCommented:
use setSize(100,100);

setPreferredSize(100,100) also will work.


Regards,
Muruga
0
 
KennywenAuthor Commented:
setPreferredSize(100,100) will return below error:

BoxAlignmentDemo.java:80: setPreferredSize(java.awt.Dimension) in javax.swing.JComponent cannot be applied to (int,int)
controlMessage.setPreferredSize(100,100);
                     ^
0
 
KennywenAuthor Commented:
thanks
0
 
GrandSchtroumpfCommented:
The actual size of your panel will depend on the LayoutManager you use.
Some managers will use the preferred size, some others will use the minimum size.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.