0

I have a renderer I've been using to draw a complex set of stuff onto a Graphics2D context, including rotated text using transforms and Graphics2D.drawString().

Now I want to see what it would take to draw stylized text, and it looks like it would be a quagmire, except that the JLabel class handles this nicely by itself if you use HTML e.g.:

<html>a<sup>2</sup> + b<sup>2</sup> = c<sup>2</sup></html>

Which of the following is a simpler approach, and how do I get started down that path?

  1. Use a JLabel to render text onto my Graphics2D context, emulating the way a JTable uses renderers by having a component like JLabel do the rendering. (which I tried doing, but I can't seem to get it to work; not sure what method to call -- paint() or paintComponents()? -- and not sure if it works with rotated graphics transforms)

  2. Parse HTML or some other simplified formatting language (like the subset of TeX used by MATLAB for graphs) and continue using drawString(), but handle the formatting myself.

4

4 回答 4

2

将此示例与您的 HTML 一起使用似乎有效:

旋转面板

于 2012-05-04T19:58:24.033 回答
2

在我看来,你最好的选择是做#1,使用你的 JLabel 作为渲染器。实际上我确实确认过一段时间你可以让标准挥杆组件旋转(显示它很容易 - 事件更棘手)

于 2012-05-04T18:00:39.050 回答
2

我使用Greg Hinkle 的 VerticalLabelUI效果很好。

我创建了一个名为 VerticalLabel 的 JLabel 子类,它会自动获取同一个包中的 VerticalLabelUI。甚至可以以这种方式与 JFormDesigner GUI 构建器一起使用!

于 2012-05-04T18:52:49.773 回答
1

你可以试试这个http://java-sl.com/vertical.html

于 2012-05-05T06:50:42.737 回答