Solved

Pixel length of String

Posted on 1998-03-07
1
1,114 Views
Last Modified: 2008-03-06
How can I decide the pixel length of a string?
0
Comment
Question by:manne
1 Comment
 
LVL 6

Accepted Solution

by:
jpk041897 earned 50 total points
Comment Utility
You use the Class java.awt.FontMetrics class. One of its methods is:

stringWidth

public int stringWidth(String str)
 
 Returns the total advance width for showing the specified String  in this Font.  The advance width is the amount by which the current point is  moved from one character to the next in a line of text.  


Example:

FontMetrics fm("Arial");
int w = fm.stringWidth("This is a String");
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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 how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

728 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

9 Experts available now in Live!

Get 1:1 Help Now