Hi
I think the problem is more: how can you detect the string is too long, isn't it? To make two strings out of one and paint both shouldn't be a problem then. So let's start...
// you have the font:
long fontSize = 12;
Font textFont = new Font("fontName", Font.BOLD, fontSize);
// use the following for the double buffering:
Image OffScreenImage = createImage(this.size().wi
Graphics OffScreenGraphics = OffScreenImage.getGraphics
OffScreenGraphics.setFont(
// now get the font metrics:
FontMetrics fontMetrics = OffScreenGraphics.getFontM
// and get the string width, finally:
long stringWidth = fontMetrics.stringWidth((S
you know the width of the string and the width of the window (or applet) now. I think that should solve your problem:
if (this.size().width < stringWidth)
{
// wrap the text here
}
Main Topics
Browse All Topics





by: jaysonjcPosted on 2000-09-07 at 04:21:22ID: 4220055
For this u need to keep track of x and y co-ordinates and when x co-ordinate is outside the panel increment y -co-ordinate appropriate for the current selected font.