PaintEvent e = new PaintEvent(this, PaintEvent.UPDATE, new Rectangle(x, y, width, height)); Toolkit.getEventQueue().postEvent(e); repaint()方法實際上是在事件隊列里加了一個UPDATE的事件,而沒有直接去重畫組件,而且這一個事件只能等待當前的事件響應方法結束之后才能被分配。因此只有繞過分配機制直接調用paint方法才能達到目的。
final String[] str = new String[1]; this.jTextArea1.setText("Please wait..."); this.paint(this.getGraphics());