Manage text and font size on a JButton

Hi;

I'd like to find some help on how to effectively maintain the display of a JButton's text proportionate to the size of the button as the button grows or shrinks in its container when the frame is resized. Thanks.
LVL 17
krakatoaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sciuriwareCommented:
The code that resizes the Button, will also practise a .setFont() and .setText()
Every time the button resizes you should create a new Font with a different size,
set it and set the text (may be redundant, you must try out).
Be sure to calculate the font size proportional to the button size: small changes must
not be carried out as the pixels on your screen could make the button and its text
grow unequally. That would be ugly.

;JOOP!
0
krakatoaAuthor Commented:
>> Be sure to calculate the font size proportional to ... [etc]

That is the part I'd like some advice on, Joopy. BTW, why do you think Java itself doesn't implement it?
0
sciuriwareCommented:
To be honest, I never used texts that grow with a growing frame.
I sometimes used growing images, but then you must work from
the original image or it will degrade.

About calculations: use the original size of the frame as start off.
Then compute the %% of horizontal and vertical changes.
Take the lesser of these 2 and use it as a factor to change a font or image
from the original size.
Hope it looks right.

;JOOP!
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

krakatoaAuthor Commented:
I knew that would be the concept. It's the tedium I was trying to avoid. ;) But I'm trying to make life difficult for myself.
0
sciuriwareCommented:
I always thought that enlarging a frame was to show more components
or to enlarge textfields.
I never saw a utility that had its buttons growing (let alone text on it)
when the frame was extended.

I did see utilities that had the option to set another font on all components
for users who wanted a larger font (disabled people).

;JOOP!
0
krakatoaAuthor Commented:
Well, I did it before, but it wasn't pretty, and I didn't bother to resize the text. But this time, I want to go the whole hog. Needless to say, getting there isn't pretty.
0
krakatoaAuthor Commented:
>>I never saw a utility that had its buttons growing (let alone <<

no, I don't think I have either.  Do you think there is any point subclassing JButton, and getting hold of the component's Graphics object, and fiddling with that?

!POOJ
(Pathetic Object Oriented Javan)
0
sciuriwareCommented:
Joop is just my first name.

Of course you could play with JButton, and when you got the JDK
you could even find all related sources in src.zip
But, to what purpose?
I confess that in my career (which is behind me now) I had some wonderful
ideas but when I asked myself "to what purpose" or "for whom" I gave most of them up.

And of some of the things I did realize, I got frustrated when my customers didn't like it
in spite of all the effort I had put into it.

;JOOP!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
krakatoaAuthor Commented:
True enough. Well thanks for the comments and experience - much appreciated. Here are some points so that you stay ahead of me. k.
0
sciuriwareCommented:
It was also my pleasure.

;JOOP!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.