我已经创建了一个矩形,现在我必须将一个JLabel放入此矩形中。所以如何将JLabel放在矩形内。如何将JLabel放在矩形内
代码在这里: -
public class ColoredRect extends JPanel
{
private double x, y, width, height;
public ColoredRect(double x,double y)
{
this.x = x;
this.y = y;
width = 100;
height =40;
rect = new Rectangle2D.Double(this.x , this.y,width,height);
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setColor(Color.cyan);
g2.fill(rect);
}
}
,请给我一些想法实现这一点。
在此先感谢。
感谢马克的快速回复......但我必须使长方形像微软visio所以用户可以编辑文本到矩形。 – user591790