【问题标题】:Java - Only Two Rounded Corners on a JFrameJava - JFrame 上只有两个圆角
【发布时间】:2015-08-15 11:48:35
【问题描述】:

我想为我目前正在从事的项目将 JFrame 的顶部两个角弄圆。我目前正在使用 setShape(new RoundRectangle2D.Double(0, 0, 200, 252, 30, 30)); 将所有四个角都修圆,但我不希望底部两个圆角我希望它是一个正常的角。

【问题讨论】:

    标签: java swing jframe rounded-corners


    【解决方案1】:

    您可以组合形状来获得它。通过将圆角矩形与普通矩形组合,您可以制作一个没有底部两个圆角的矩形。

    例如

    public class example extends JFrame{
    
        public example() {
            this.setUndecorated(true);
            this.getContentPane().setBackground(Color.red);
    
            Area shape1 = new Area(new RoundRectangle2D.Double(0, 0, 200, 252, 30, 30));
            Area shape2 = new Area(new Rectangle(0, 252-30, 200, 100));
            shape1.add(shape2);
            this.setShape(shape1);
            this.setSize(300, 400);
        }
        public static void main(String[] args) {
            new example().setVisible(true);
        }
    
    }
    

    或者,您可以为框架提供比 RoundRectangle 矩形更小的高度。这样您就看不到 RoundRectangle 的底部。然后您可以获得所需的输出

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-18
      • 2021-10-02
      • 1970-01-01
      • 2020-04-02
      • 2020-01-07
      • 1970-01-01
      • 2015-06-19
      • 1970-01-01
      相关资源
      最近更新 更多