Solved

JPanel setPreferred width

Posted on 2011-09-27
9
267 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
Comment Utility
setPreferredSize
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
0
 

Author Comment

by:dshrenik
Comment Utility
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
Comment Utility

you can use
public Dimension getPreferredSize()

0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 47

Expert Comment

by:for_yan
Comment Utility
and then Dimension.width
will give you the width
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
Comment Utility
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
Comment Utility


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

Assisted Solution

by:CEHJ
CEHJ earned 250 total points
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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 contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

763 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

12 Experts available now in Live!

Get 1:1 Help Now