Usually the buttons get sized by the Layout used.
which layout are you using?
if u r using JPanel the default is FlowLayout,
in this case Flowlayout doesn't control the width just the placement.
so before u add the button 2 the panel use
button.setPreferredSize(new Dimension(100,100));
or
button.setSize(100,100);
avdzm
> can only change button's height, but not width, why?
Because you have a coding problem. How many times do you need to be asked to post a SSCCE?
If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program[/url] (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] so the code retains its original formatting.
Every question you post should have a SSCCE, so we don't waste time quessing what you are doing. 95% of the time when you create the SSCCE you will find your problem.
The part of "why" is actually simple.
Some layout managers will auto expand component width/height to fill the container, such as borderlayout, or grid layout in your case.
The part "how to solve it" is the challenge.
Apparently the way to "hack" this behaviour is to put your buttons into a JPanel with layout manager that wont auto expand, such as flow layout. You need to tell me how you want your button arranged for further help =)