Drawing dashed line in java

前端 未结 3 832
甜味超标
甜味超标 2020-12-16 10:47

My problem is that I want to draw a dashed line in a panel, I\'m able to do it but it draw my border in dashed line as well, which is oh my god!

Can someone please e

3条回答
  •  情歌与酒
    2020-12-16 11:07

    You modified the graphics context by setting a stroke, and subsequent methods such as paintBorder() use the same context and thus inherit all modifications you made.

    Solution: clone the context, use it for painting and dispose it afterwards.

    Code:

    // derive your own context  
    Graphics2D g2d = (Graphics2D) g.create();
    // use context for painting
    ...
    // when done: dispose your context
    g2d.dispose();
    

提交回复
热议问题