Java – dimension, changing width / height only
•
Java
How do I change the width or height of only the components that need a dimension object? Now I do this:
jbutton.setPreferredSize(new Dimension(button.getPreferredSize().width,100));
But I have a feeling that I did it the wrong way If there is a better way, what is the best way?
Solution
First, you didn't change JButton's dimension You are specifying the desired preferred size, which can eventually be applied to your JButton. Based on the layoutmanager of the inserted component
It doesn't matter what concerns you use the dimension object Finally, you can access dimension fields directly:
Dimension d = button.getPreferredSize(); d.height = 10; jbutton.setPreferredSize(d);
But this is almost the same thing
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码