简体   繁体   English

带边框的Java绘制线

[英]Java draw line with border

I'm developing a JApplet in which the user can draw some lines over an image. 我正在开发一个JApplet,用户可以在其上绘制一些图像线。 Lines can be red or green, but I need to highlight them because I don't know the background color. 线条可以是红色或绿色,但我需要突出显示它们,因为我不知道背景颜色。

So I thought that I can draw a white "border" to the line, and I tried to do this creating other two white lines to the left and to the rigth of the original one. 所以我认为我可以在线上绘制一个白色的“边框”,我试图在左边创建另外两条白色线条并在原始线条的边缘创建。 But the result is poor. 但结果很糟糕。

Is there a better way to accomplish this goal? 有没有更好的方法来实现这一目标?

As mentioned by @Jesper, draw the line first using a thicker Stroke (as seen in this answer ). 如@Jesper所述,首先使用较粗的Stroke绘制线条(如本答案所示 )。

The black outline on the letters has width 2. 字母上的黑色轮廓宽度为2。

g.setStroke(new BasicStroke(2f));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM