当我单击形状时,为了显示“选择”,我想调用方法drawSelected,该方法将重新绘制形状以显示它已被选中。像这样:https://gyazo.com/6e115bdca55aaecd70ebada7e046475d方形部分如何变厚。

为此,我需要一个边框,我可以通过执行以下操作来弄清楚该怎么做:

// Set paint to the random color
g2.setPaint(getColor());
g2.fill(rectangle);
// Set the border of shape to black
g2.setPaint(Color.black);
g2.draw(rectangle);


但是现在当我单击一个矩形时,显示选择的方法仍然使用平移,并且得到以下结果:https://gyazo.com/07857f6782c3a32dc90946e79736374d其中只有顶部和左侧变粗。

我知道底部和右侧也正在绘制,只是因为它们被另一种颜色填充,所以它们与前一个矩形重叠,因此您看不到它。

我的问题是,如何将边框的厚度更改到什么地方而不是平移形状,而可以使用较粗的边框重新绘制形状以显示选择内容?

最佳答案

如您所述,最好的方法是使用较粗的边框重绘:

Graphics2D g2 = (Graphics2D) g;
g2.setStroke(new BasicStroke(10));
g2.setPaint(Color.black);
g2.draw(rectangle);

关于java - 如何加粗形状的边框,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33812357/

10-10 03:46