Java - JFrame 上只有两个圆角
Java - Only Two Rounded Corners on a JFrame
我想为我目前正在处理的项目将 JFrame 的顶部两个角圆角化。我目前正在使用 setShape(new RoundRectangle2D.Double(0, 0, 200, 252, 30, 30));
对所有四个角进行四舍五入,但我不希望底部的两个角变圆,我希望它成为一个普通的角。
你可以组合形状得到 this.By 将圆角矩形与普通矩形组合你可以制作一个没有底部两个圆角的矩形。
例如
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 的底部。然后您可以获得所需的输出
我想为我目前正在处理的项目将 JFrame 的顶部两个角圆角化。我目前正在使用 setShape(new RoundRectangle2D.Double(0, 0, 200, 252, 30, 30));
对所有四个角进行四舍五入,但我不希望底部的两个角变圆,我希望它成为一个普通的角。
你可以组合形状得到 this.By 将圆角矩形与普通矩形组合你可以制作一个没有底部两个圆角的矩形。
例如
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 的底部。然后您可以获得所需的输出