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 ?
text size or the image size. Is there anyway to set
the width and height for JButton ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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);
-------------------------- ---------- ---------- ---------- ---
--------------------------
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);
--------------------------
ASKER