We help IT Professionals succeed at work.

setting the JButton length according to text displayed

hipal
hipal asked
on
397 Views
Last Modified: 2012-05-10
How can I set the JButton length according to text displayed ?

Using setSize() I have to everytime adjust it according to want I want as text on button.

thanks!
Comment
Watch Question

Commented:
Hi,

Do you use a LayoutManager class?

Please take a look at this :

http://download.oracle.com/javase/1.4.2/docs/api/java/awt/FlowLayout.html
http://download.oracle.com/javase/tutorial/uiswing/layout/using.html
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2016

Commented:
>> How can I set the JButton length according to text displayed ?

With most  layout managers it does this automatically. Which one are you using?

Author

Commented:
I am not using any layout manager .. in that cas e??

Commented:
try pack() , it will adjust it automatically no ??
CERTIFIED EXPERT

Commented:
read my link, it's exactly for buttons places in panel without  any layout manager...
CERTIFIED EXPERT

Commented:
@alpharom
JButton doesn't have pack method

Commented:
@Valeri
Sorry, i thought it did !!!
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.