tallpsmith
tallpsmith

Reputation: 287

Automatically scaling font to fit panel

I have an Swing app whose main panel is divided into a 3x2 grid of charts, and the app can be resized, with the charts (JFreeChart) auto scaling. One of these panels I would like to display the Apdex rating in, which is just text (e.g. '0.89 [0.5]*'). We use the application to display on a monitor visible to everyone, and scale multiple instances of the app that monitor different data centers. Scaling the Apdex font size to fit available panel space is what I'm after.

Any good ideas?

Upvotes: 2

Views: 744

Answers (2)

trashgod
trashgod

Reputation: 205785

I'd render it off-screen at some suitably large point size, as shown here, and then down-sample it using AffineTransformOp, as shown here.

Upvotes: 2

Boro
Boro

Reputation: 7943

After re-reading and rethinking the question I would suggest for you to try calculating it yourself by use of FontMatrics stringWidth with the string and iteratively increasing the font size until you can, i.e. the size evaluated by you versus the available space.

A ready algorithm would be nice but I didn't hear of any.

Good luck, Boro.

Upvotes: 2

Related Questions