如何制作jfreechart传奇圆角

时间:2014-05-05 21:13:11

标签: java-ee jfreechart

如何在系列传说所在的框架中绘制圆角?

我希望它看起来像下图: enter image description here

感谢您的帮助

2 个答案:

答案 0 :(得分:2)

您可以将看到here的圆角边框应用于自定义图例面板here

答案 1 :(得分:1)

经过一番研究,我终于解决了。

这很简单,只需要问char的传奇然后是它的框架。最后使用要在图例中使用的基本形状覆盖BlockFrame界面。

     jfreechart.getLegend().setFrame(new  BlockFrame() {

        /** The space reserved for the border. */
        private RectangleInsets insets = new RectangleInsets(1, 1, 1, 1);

        /** The border color. */
        private transient Paint paint = new Color(117,170,219);

        @Override
        public RectangleInsets getInsets() {
            return insets;
        }

        @Override
        public void draw(Graphics2D g2, Rectangle2D area) {
            Dimension arcs = new Dimension(45,45);
            double t = this.insets.calculateTopInset(area.getHeight());
            double b = this.insets.calculateBottomInset(area.getHeight());
            double l = this.insets.calculateLeftInset(area.getWidth());
            double r = this.insets.calculateRightInset(area.getWidth());
            double x = area.getX();
            double y = area.getY();
            double w = area.getWidth();
            double h = area.getHeight();
            g2.setPaint(this.paint);
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);


            RoundRectangle2D myrect= new RoundRectangle2D.Double();

            if (t > 0.0) {
                myrect.setRoundRect(x, y, w, t,arcs.width, arcs.height);
                g2.fill(myrect);
            }
            if (b > 0.0) {
                myrect.setRoundRect(x, y + h - b, w, b,arcs.width, arcs.height);
                g2.fill(myrect);
            }
            if (l > 0.0) {
                myrect.setRoundRect(x, y, l, h,arcs.width, arcs.height);
                g2.fill(myrect);
            }
            if (r > 0.0) {
                myrect.setRoundRect(x + w - r, y, r, h,arcs.width, arcs.height);
                g2.fill(myrect);
            }
        }
    });