Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 326
  • Last Modified:

JPanel setPreferred width

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
dshrenik
Asked:
dshrenik
  • 6
  • 2
2 Solutions
 
CEHJCommented:
setPreferredSize
0
 
for_yanCommented:
0
 
dshrenikAuthor Commented:
But I want to get the preferred size and use the width property, and change the height.

preferredSize() is deprecated.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
for_yanCommented:

you can use
public Dimension getPreferredSize()

0
 
for_yanCommented:
and then Dimension.width
will give you the width
0
 
for_yanCommented:
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
 
for_yanCommented:
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
 
for_yanCommented:


I think this should be equivalent:
chartPanel.setSize(chartPanel.getPreferredSize().width, 100);
0
 
CEHJCommented:
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now