如何制作可以将可编辑文本作为微软visio或gliffy的矩形。 我已经实现了可拖动的矩形,但是我无法将文本放在其中,可以在运行时编辑为microsoft visio或gliffy。所以请给我一些想法来实现它。
代码: - 公共类ColoredRect扩展了JPanel {
private double x, y, width, height;
private Rectangle2D.Double rect;
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);
}
public void setRectangle(double x, double y)
{
this.x =x;
this.y =y;
rect.setFrame(this.x,this.y,this.width,this.height);
repaint();
}
}
提前感谢。