![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Nov 2005
Posts: 149
Rep Power: 3
![]() |
drawString size?
I am creating my own button class in an applet, and I'm planning to use the g.drawString() method, but I need to know the size of the text when it's drawn to know how big to draw the border around it. Are there any methods that return the size a given string would be if it were to be drawn?
|
|
|
|
|
|
#2 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
I know that the FontMetrics class can help find the size of characters -- don't know if that helps you at all.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
|
|
#3 |
|
Expert Programmer
|
If you are extending JButton, you can use the setFont(Font f) method, for example:
setFont(new Font("Helvetica", Font.PLAIN, 24)) |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Nov 2004
Posts: 84
Rep Power: 4
![]() |
Ditto on the Font Metrics. This might help you a little bit:
http://www.ictp.trieste.it/~manuals/...awingText.html
__________________
HijackThis Team-SFDC |
|
|
|
|
|
#5 |
|
Expert Programmer
|
I think buttons automatically resize themselves depending on the length of their text, so if you don't specify a size you may be able to use the setBorder(Border b) method and save yourself the trouble.
|
|
|
|
|
|
#6 | |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,038
Rep Power: 5
![]() |
Quote:
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
|
|
|
#7 |
|
Expert Programmer
|
If what you want is a button that is simply a color background with a border and text, all you need to do is add the code:
setBackground(Color.white); setBorder(BorderFactory.createLineBorder (Color.black, 1)); |
|
|
|
|
|
#8 |
|
Hobbyist Programmer
Join Date: Nov 2005
Posts: 149
Rep Power: 3
![]() |
I'm using the fontMetrics thing right now, and it's working great =) thanks.
|
|
|
|
|
|
#9 |
|
Hobbyist Programmer
Join Date: Nov 2005
Posts: 149
Rep Power: 3
![]() |
I had a related question, though... Is there a way to underline certain letters in string when drawing it?
|
|
|
|
|
|
#10 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
Can't you just make a new Font that automatically underlines?
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|