hi,
how can i change the size of JButton ( i want the size of JButton to be 25X25)...
i used setPreferredSize(Dimension d) method but it didn't work with me??!!
[HIGHLIGHT="Java"]setPreferredSize(new Dimension(25, 25))[/HIGHLIGHT]
Will work unless you have a layout manager that overrides manual changes, and there may be other reasons, but of course I can not say for sure because you give no example of your code.
Sorry for bringing this thread back from the dead but I had a question regarding the topic.
setPreferredSize will work but JButtons, but not if I have a setLayout(GridLayout) right?
Nope, the gridlayout gives all components inside it the same width / height.
A boxLayout puts all components in a SINGLE row or column without affecting them. (BoxLayout)
Now because it's much likely you want multiple rows or columns i suggest you try to put panels in a gridLayout and the panels set up with a boxLayout
Like this if you know what i mean:
Code:-------------GRIDLAYOUT-------------- | B | B | B | B | | O | O | O | O | | X | X | X | X | | | | | | | | | | | -------------------------------------
Nvm I found out, John was right, this worked:
ButtName.setPreferredSize(new Dimension(buttonWidth, buttonHeight));
I'm also having this problem. I used this code:but I'm getting this error:Code:ButtName.setPreferredSize(new Dimension(buttonWidth, buttonHeight));How do I declare or instantiate "Dimension"?Code:cannot find symbol symbol : class Dimension
Thanks!
Try to import
Code:java.awt.Dimension; OR java.awt.*;
wow! That worked! Thanks!
There are currently 4 users browsing this thread. (0 members and 4 guests)
Bookmarks