当我调用fillRoundRect()时,只有1个角是圆角的 [英] Only 1 Corner is Rounded when I call fillRoundRect()
本文介绍了当我调用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);
}
}
我得到一个只有一个圆角边的规则矩形.请参见下图.
I get a get a regular rectangle with only 1 rounded side. Please see the image below.
这是预期的功能吗? 如果没有,我该如何解决.
Is this the expected function? If not, how can I fix this.
如果执行以下操作,我可以得到2个圆角:
g2.fillRoundRect(0, 0, 50, 50, 7, 7);
I can get 2 rounded corners if I do this:
g2.fillRoundRect(0, 0, 50, 50, 7, 7);
推荐答案
我唯一能想到的就是包含矩形的窗口太小,并且切掉了其他三个角,但这似乎不太可能.
The only thing I can really think of is that the window containing the rectangle is too small and is cutting off the other three corners, but that seems pretty unlikely.
这篇关于当我调用fillRoundRect()时,只有1个角是圆角的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文