button11.setSize(60, 60);but it isnt working I am using a GridLayout does that keep me from being able to change size?
JButton
Started by wildbill, Apr 29 2010 06:53 PM
4 replies to this topic
#1
Posted 29 April 2010 - 06:53 PM
Ok I need a JButton to resize and I have tried
|
|
|
#2
Posted 29 April 2010 - 08:13 PM
The JButton uses his prefferedSize(). It calculates how much width and height it will need by watching how many characters has to display.
Ex: JButton buttonOne = new JButton("Yes"); JButton buttonTwo = new JButton("This will be a larg ebutton");
In this casse, buttonTwo will be a couple of times bigger than buttonOne, even if you setSize() to both of them.
To resolve this issue, you can change the font name, or you can make another panel in the region where your buttons are, so it will get the width only of the region.
Ex: JButton buttonOne = new JButton("Yes"); JButton buttonTwo = new JButton("This will be a larg ebutton");
In this casse, buttonTwo will be a couple of times bigger than buttonOne, even if you setSize() to both of them.
To resolve this issue, you can change the font name, or you can make another panel in the region where your buttons are, so it will get the width only of the region.
// d-_-b+
#3
Posted 30 April 2010 - 04:07 AM
so pretty much the size will always be small if I dont put text in them.
#4
Posted 30 April 2010 - 05:26 AM
Well, if you want an empty button, you can set his preferred size.
JButton button = new JButton();
button.setPreferredSize(new Dimension(int width, int height));
The Dimension class is located in java.awt.Dimension; which you'll have to import. Or you can play with other layouts.
JButton button = new JButton();
button.setPreferredSize(new Dimension(int width, int height));
The Dimension class is located in java.awt.Dimension; which you'll have to import. Or you can play with other layouts.
// d-_-b+
#5
Posted 30 April 2010 - 05:46 AM
Thank you


Sign In
Create Account


Back to top









