Link to home
Start Free TrialLog in
Avatar of andric
andric

asked on

How to set width and height for JButton ?

By default, the JButton's size is according to the
text size or the image size. Is there anyway to set
the width and height for JButton ?
Avatar of andric
andric

ASKER

Urgent!
ASKER CERTIFIED SOLUTION
Avatar of chris_kabuki
chris_kabuki

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of andric

ASKER

Thanks. It's works ! But, you must set the layout to null for where the button reside. Otherwise, the setting will not take place.

-----------------------------------------------------------
JPanel p = new JPanel();
// Set layout to null
p.setLayout(null);

JButton myButton = new JButton();
// Do all your set's etc here

// i.e. x-coord = 0, y-coord = 0, width = 100, height = 20
myButton.setBounds(0, 0, 100, 20);

p.add(myButton);
-----------------------------------------------------------