【发布时间】:2015-02-22 03:24:59
【问题描述】:
我想创建一个可以设置图像的圆形 JLabel。与在 Google+ 中一样,有一个圆形的个人资料相框。我遇到了一个问题,即我试图在 JLabel 中设置的图像出现在整个屏幕上,但不在所需的圆形 JLabel 中。我的代码是这样的。
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.*;
public class OverJLabel extends JLabel{
public int intX,intY,w,h;
public OverJLabel(int x,int y,int width,int height,Icon image) {
super(image);
intX=x;
intY=y;
w=width;
h=height;
}
@Override
public void paintComponent(Graphics g){
super.paintComponent(g);
g.setColor(Color.RED);
g.drawOval(intX, intY, w, h);
}// end of the overriden label
}// end of the rounded shape JLabel class
【问题讨论】:
-
这段代码对我有用。