?
Solved

How to set width and height for JButton ?

Posted on 2001-07-03
3
Medium Priority
?
2,572 Views
Last Modified: 2012-06-27
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
Comment
Question by:andric
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

by:andric
ID: 6251109
Urgent!
0
 
LVL 1

Accepted Solution

by:
chris_kabuki earned 300 total points
ID: 6251184
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
 

Author Comment

by:andric
ID: 6251460
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question