[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Manage text and font size on a JButton

Posted on 2008-01-29
10
Medium Priority
?
1,178 Views
Last Modified: 2008-01-30
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.
0
Comment
Question by:krakatoa
  • 5
  • 5
10 Comments
 
LVL 24

Expert Comment

by:sciuriware
ID: 20775122
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
 
LVL 17

Author Comment

by:krakatoa
ID: 20775431
>> 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
 
LVL 24

Expert Comment

by:sciuriware
ID: 20777058
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 17

Author Comment

by:krakatoa
ID: 20777663
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
 
LVL 24

Expert Comment

by:sciuriware
ID: 20778342
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
 
LVL 17

Author Comment

by:krakatoa
ID: 20778877
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
 
LVL 17

Author Comment

by:krakatoa
ID: 20779210
>>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
 
LVL 24

Accepted Solution

by:
sciuriware earned 1400 total points
ID: 20780111
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
 
LVL 17

Author Comment

by:krakatoa
ID: 20781332
True enough. Well thanks for the comments and experience - much appreciated. Here are some points so that you stay ahead of me. k.
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 20784409
It was also my pleasure.

;JOOP!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses
Course of the Month8 days, 11 hours left to enroll

613 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