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

后端 未结 5 828
佛祖请我去吃肉
佛祖请我去吃肉 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:02

    The Swing experts who know what they're talking about will be here shortly. In the meantime, let me comment on this:

    Now, my question relates to wether this is a good idea? I do after all repaint the parent component from a child component. I wonder if this lead to a loop of repaints? If the parent tries to repaint its children and the children tries to repaint its parent - then i assume we're talking about a loop.

    Once you try it out and see that it's not a problem on your machine, chances are that it will be true on all JVMs you try. That is to say, the proof is in the pudding, or random bumbling does generally lead to positive results in Swing. Recursive loops have a way of causing the program to halt pretty quickly in Java, so the answer is... if this were totally wrong you'd already know. Plus you can put sysouts in there to see if this is happening (it's obviously not).

    That said, there may be a better way to deal with your problem, but if your answer works, stick with it for now.

提交回复
热议问题