先列举下swing中的JFrame的相关painting方法:Component:paintAll()
-Container:paint(),paintComponents()
--Window
---Frame
----JFrame:那么,对于一个JFrame来说,当painting它时,这三个继承来的方法,到底是哪个在起作用呢?
           或者,它们相互间存在着什么调用关系?还是遵循着某种优先级呢?另外一个问题,JLabel是不是不能通过setBackground()来设置background的?其他的JComponent组件都可以,好像就这个JLabel不行,那么怎么来设置JLabel的background呢?有劳各位大侠了,谢谢!
  

解决方案 »

  1.   

    http://java.sun.com/products/jfc/tsc/articles/painting/index.html
    有时候瞎用了两年swing的人都不清楚一些基础问题,这个问题问得好
      

  2.   

    多谢 DanielYWoo(绿色毒汁) 大侠.
     http://java.sun.com/products/jfc/tsc/articles/painting/index.html 中好像没有提到
    paintAll()和paintComponents()这两个方法,而且大家也好少提到这两个方法,是不是它们只
    是个摆设的作用?
      

  3.   

    JLabel默认是背景透明的,因此调用setBackground()设置背景色后,要用setOpaque(true)将其背景设为不透明才有效。