> captain i think this is what i want (FontMetrics)
> but why cannot i do this.
>
> FontMetrics metrics = new FontMetrics();
>
> secondly tave how did you figure out the height and
> width of a text then?
Because the only constructor is:
FontMetrics
protected FontMetrics(Font font)
Creates a new FontMetrics object for finding out height and width
information about the specified Font and specific character glyphs in that
Font.
Parameters:
font - the Font
class AddTextListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
FontMetrics metrics = textField.getFontMetrics(font);
int fontHeight = metrics.getHeight();
String text = textField.getText();
int textWidth = metrics.stringWidth(text);
resultLabel.setText(textWidth);//error is here
}
}
i know it will take string but how can i convert it into int? i tried Integer.ParseInt(resultLabel.getText()) but still not working because resultLabel is a string.