Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dimension, Only changing the width/height

How do I only change the width or height of a component that requires a Dimension object? Currently I do it like this:

jbutton.setPreferredSize(new Dimension(button.getPreferredSize().width, 100));

But I have a feeling that I'm doing it the wrong way. What is the best way to approach this if there is a better way?

like image 346
Patrick Avatar asked Aug 24 '11 14:08

Patrick


People also ask

Is width and height same?

The length, width and height are the dimensions of a geometrical figure that depict how long, wide and high a figure is. While length is the longest side of a figure, width is the shorter side and height is the vertical dimension of the figure.

What comes first width or height?

The Graphics' industry standard is width by height (width x height). Meaning that when you write your measurements, you write them from your point of view, beginning with the width. That's important.

How do you write dimensions?

All box dimensions are written as length x width x height. For example, 14" x 11" x 4" means 14" (L) x 11" (W) x 4" (H)".

Why should you include the height and width specifications for all images?

Web performance advocates have often advised to add dimensions to your images for best performance to allow the page to be laid out with the appropriate space for the image, before the image itself has been downloaded.


1 Answers

First of all you are not changing the dimension of JButton. You are specifying the desired preferred size, that can be eventually applied to your JButton depending on the LayoutManager of the component it's inserted into.

For what concern the use of Dimension object that's fine. Eventually you can access directly Dimension field:

Dimension d = button.getPreferredSize();
d.height = 10;
jbutton.setPreferredSize(d); 

but that's pretty much the same thing.

like image 107
Heisenbug Avatar answered Nov 11 '22 04:11

Heisenbug