Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2588
  • Last Modified:

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 ?
0
andric
Asked:
andric
  • 2
1 Solution
 
andricAuthor Commented:
Urgent!
0
 
chris_kabukiCommented:
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);
0
 
andricAuthor Commented:
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);
-----------------------------------------------------------
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now