java-当我调用fillRoundRect()时,只有1个角是圆角的

提问

运行此代码时:

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import javax.swing.JButton;
import javax.swing.JLabel;

public class CustomButton extends JButton {

    int width = 100;
    int height = 50;
    int radius = 10;
    JLabel lab;

    @Override
    protected void paintComponent(Graphics g) {
        Graphics2D g2 = (Graphics2D) g;

        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setColor(Color.ORANGE);
        g2.fillRoundRect(0, 0, width, height, radius, radius);

        g2.dispose();
        super.paintComponent(g2);
        super.paintComponent(g);

    }

}

而我的另一堂课:

package custom.frame;

import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class CustomFrame {

    public static void main(String[] args) {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setLayout(new FlowLayout());
        f.setSize(500,500);
        f.setLocationRelativeTo(null);

        JPanel pane = new JPanel();
        pane.setBounds(0,0,500,500);

        CustomButton btn = new CustomButton();
        pane.add(btn);
        f.add(btn);
        f.setVisible(true);

    }

}

我得到一个只有1个圆角边的规则矩形.请参见下图.

这是预期的功能吗?
如果没有,我该如何解决.

编辑

如果这样做,我可以获得2个圆角:
g2.fillRoundRect(0,0,50,50,7,7);

最佳答案

我唯一能想到的就是包含矩形的窗口太小,并且切掉了其他三个角,但这似乎不太可能.