When does a JPanel paint (or repaint) its child components?

后端 未结 5 818
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-11 21:17

I\'ve got a JButton which is painted using a custom UI delegate (CustomButtonUI extends BasicButtonUI). The CustomButtonUI\'s paint() method draws the button with rounded \"

5条回答
  •  不知归路
    2020-12-11 22:09

    AFAIK, repaint() just tells the system to repaint that component in the next paint cycle, i.e. if you call repaint() in a paint() method the repaint might be done in the next cycle.

    Generally, Swing runs in its own thread, so repeated repaint should not stop the application logic. However, it might be using processing power, if the system always repaints the ui even if there are no changes.

    You could try and write a log message to see when and how often the button is painted. If that happens continously even if nothing happens that would cause a ui update, you might have to find a solution. If not, you should be fine.

    Edit: there is a class called RepaintManager that you might find interesting.

提交回复
热议问题