Re: Text width
From: Chris (chris2k01_at_hotmail.com)
Date: 02/28/04
- Previous message: Chris: "Re: JAVA ResultSet Problem?"
- In reply to: Oskar Sigvardsson: "Text width"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 28 Feb 2004 04:21:43 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Oskar Sigvardsson wrote:
> Hello,
>
> I need to know how to get get the width of a string without having a
> java.awt.Graphics around (otherwise i'd just
> graphics.getFontMetrics().stringWidth("Hello I'm a string") )
>
> The thing is that I have I function that returns an Image with the
> text, and I want to create the Image inside the function. The size
> of the Image is determined by how big the text is, but to get the
> size of the text I need to have an Image, and to get the Image I
> need to know the size of the text. So I'm in a catch-22 hell and I
> don't know how to get out (I suppose I could create a temporary
> Image and use that for determining the size and then discard it and
> create another Image with the correct size but there has to be a
> better way.)
>
> Any help appriciated
> Oskar Sigvardsson
Hi,
I'm really not about to figure out how this works, but a good place to
start looks like java.awt.Font.getStringBounds(), with an
appropriately prepared FontRenderContext designed to simulate the
Image you'll eventually be creating. That'll give you the size you
need.
- --
Chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
iD8DBQFAP+0pnwjA8LryK2IRAntmAJ95U1kqoC5yTl9BH91XjdxVDOn3dwCgmjYy
WB85ddQUAqdjU+RdHhEe8OU=
=HesH
-----END PGP SIGNATURE-----
- Previous message: Chris: "Re: JAVA ResultSet Problem?"
- In reply to: Oskar Sigvardsson: "Text width"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|