Java 奇怪的矩形渲染

Java weird rectangle rendering

请问是不是bug

当我使用 fillRect 方法时,它会呈现一个比 drawRect 方法小一个像素的矩形。

有没有人遇到和我一样的问题? :( 或者是否存在解决此问题的方法?

下面是一个小示例代码:

public Frame(){
    super("Sample rectangle");
    setExtendedState(this.getExtendedState() | JFrame.MAXIMIZED_BOTH);
    setUndecorated(true);       
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLocationRelativeTo(null);
    setVisible(true);
}

public void paint(Graphics g){
    g.setColor(Color.BLACK);
    g.fillRect(0,0, getWidth()-1, getHeight()-1);

    g.setColor(Color.RED);
    //g.drawRect(0,0, getWidth()-1, getHeight()-1);
    //wrap.graphics(g);
}

此行为与相关 Javadoc 中描述的完全一致:

fillRect Fills the specified rectangle. The left and right edges of the rectangle are at x and x + width - 1. The top and bottom edges are at y and y + height - 1

drawRect Draws the outline of the specified rectangle. The left and right edges of the rectangle are at x and x + width. The top and bottom edges are at y and y + height.

根据 Javadoc(强调我的):

drawRect

Draws the outline of the specified rectangle. The left and right edges of the rectangle are at x and x + width. The top and bottom edges are at y and y + height. The rectangle is drawn using the graphics context's current color.

fillRect

Fills the specified rectangle. The left and right edges of the rectangle are at x and x + width - 1. The top and bottom edges are at y and y + height - 1. The resulting rectangle covers an area width pixels wide by height pixels tall. The rectangle is filled using the graphics context's current color.