Solved

How to set width and height for JButton ?

Posted on 2001-07-03
3
2,533 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
  • 2
3 Comments
 

Author Comment

by:andric
ID: 6251109
Urgent!
0
 
LVL 1

Accepted Solution

by:
chris_kabuki earned 100 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
mergeTwo  challenge 13 72
where is session ID cache stored 1 39
bitbucket vs gitbucket 3 32
Java array passed to SQL where clause 23 43
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now