[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 331
  • 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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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