Solved

set JPanel size

Posted on 2004-04-16
5
372 Views
Last Modified: 2012-06-27
How can i set the JPanel size?

Can i use setPreferredSize(100,100);?

thanks
0
Comment
Question by:Kennywen
  • 2
  • 2
5 Comments
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10840273
use setSize(100,100);

setPreferredSize(100,100) also will work.


Regards,
Muruga
0
 

Author Comment

by:Kennywen
ID: 10840317
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
 
LVL 9

Accepted Solution

by:
mmuruganandam earned 25 total points
ID: 10840332

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

This will work.
0
 

Author Comment

by:Kennywen
ID: 10840347
thanks
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 10840506
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now