开发者

Automatically scaling font to fit panel

开发者 https://www.devze.com 2023-02-24 03:03 出处:网络
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 dis开发者_运维知识库

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 dis开发者_运维知识库play 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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消