用paintComponent()方法,最后再调用updateUI()试一下,不行就自己写个UI。

解决方案 »

  1.   

    抱歉,paintComponent()和updateUI()都是swing的:)
      

  2.   

    sorry, paintComopnent()是Container的。但是对Label仍然不起作用的。
      

  3.   

    g.drawRect(1, 1, this.getWidth()-1, this.getHeight()-1);
    看看能出来不能
      

  4.   

    使用drawRect(x,y,width,height)画出的框大小应该是(width+1,height+1)
    所以画框的代码应改为
    public void paint(Graphics g) {
        super.paint(g);
        g.setColor(this.getBackground());
        g.fillRect(0, 0, this.getWidth(), this.getHeight());
        g.setColor(this.getForeground());
        g.drawRect(0, 0, this.getWidth()-1, this..getHeight()-1);
    }
    另外,圆角框线应该使用drawRoundRect方法。
      

  5.   

    补充:
    右下角的坐标是(x+width+1,y+height+1);ksxy (空山新雨)的代码画
    到了Label的外面,所以看不到。
      

  6.   

    cpu的说法没错,但是……起码应该看到左上的线的。我最后用panel解决的方法如下:    /**
         * Override this method to implement customized painting.
         * @param g the Graphics.
         */
        public void paint(Graphics g) {
            g.setColor(borderColor);
            g.drawRect(0, 0, this.getWidth() - 1, this.getHeight() - 1);
            g.drawString(" " + tipString + " ", 0, this.getHeight() - 4);
        }我觉得先前的代码起码应该看到点东东,问题是什么也看不到啊。
      

  7.   

    呵呵,你把getWidth()和getHeight()的值打出来看看,搞不好都是0
      

  8.   

    public void paint(Graphics g) {
        super.paint(g);
        if(isVisible());//加这样一句试试.
        g.setColor(this.getBackground());
        g.fillRect(0, 0, this.getWidth(), this.getHeight());
        g.setColor(this.getForeground());
        g.drawRect(0, 0, this.getWidth()-1, this..getHeight()-1);
    }
      

  9.   

    补充一下.你画的都给你画了,但是.画的时候你的界面还没显示出来.
    如果你改变一下label的大小是不是就显示出来啦.