如何在java swing中制作椭圆JPanel TitledBorder?

时间:2015-02-23 16:48:34

标签: java swing jpanel

enter image description here 如何在java swing TitledBorder或任何其他面板中绘制这个? 我尝试了以下代码并且没有工作,继续绘制半椭圆,另一半被切割。

@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width,
        int height) {
    Graphics2D g2 = (Graphics2D)g;      
    g2.setColor(Color.BLUE);

    FontMetrics m = c.getFontMetrics(getTitleFont());

    Ellipse2D shape = new java.awt.geom.Ellipse2D.Float(2, -20,m.stringWidth(title)+10, m.getHeight()+40);


    g2.fill(shape);
    g2.draw(shape);
    super.paintBorder(c, g, x, y, width, height);


}

0 个答案:

没有答案