Solved

JPanel setPreferred width

Posted on 2011-09-27
9
280 Views
Last Modified: 2012-05-12
Can you tell me the alternative to preferredSize()? It is deprecated in the current version of java.

I want to do this:
chartPanel.setSize(chartPanel.preferredSize().width, 100);
chartPanel is a JPanel.

Thanks!
0
Comment
Question by:dshrenik
  • 6
  • 2
9 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 36713400
setPreferredSize
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36713417
0
 

Author Comment

by:dshrenik
ID: 36713420
But I want to get the preferred size and use the width property, and change the height.

preferredSize() is deprecated.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36713427

you can use
public Dimension getPreferredSize()

0
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.

 
LVL 47

Expert Comment

by:for_yan
ID: 36713430
and then Dimension.width
will give you the width
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36713436
after you get Dimension you can create a new Dimension(olddim.width+some, olddim.height)
and set it as a new new preferred szie
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36713444
In general don't be afraid so much of yusing deprecated if it is conveninent to you - it writes the compiler warning,
but it works
0
 
LVL 47

Accepted Solution

by:
for_yan earned 250 total points
ID: 36713452


I think this should be equivalent:
chartPanel.setSize(chartPanel.getPreferredSize().width, 100);
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 250 total points
ID: 36713456
Avoid deprecated methods (they're not deprecated for fun ;))

Just add to the width or height as you see fit, having got the Dimension with getPreferredSize
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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

932 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