1

I'm doing something very arbitrary, and mainly due to my OCD, but to make a long story short I'd like to remove the asynchronous update on JButtons and invoke repaint() when buttons need to be changed.

Is there any way to do this short of overwriting the overwritten imageUpdate method that JButton implements? I'm working on an assignment and can only turn in a limited number of files.

I appreciate any responses :)

Seeing as it's homework, and I'm in a very large class with some fairly strict regulation against cheating/copy-pasting, I don't feel comfortable with posting my sample code. I'd prefer if any answers were hypothetical! Thanks again for any help.

4

2 回答 2

0

If it is something you can do with JLabel or JPanel, or one of them with JButton, I would strongly suggest you do so.

JButton is unreliable when it comes to updating status.

If using JButton is absolutely necessary, can you explain what you want to make out of it in greater detail?

于 2013-04-12T21:27:55.627 回答
0

通常,当想要控制组件绘制时,应该像这样覆盖paintComponent

new javax.swing.JButton(){
    @Override
    protected void paintComponent(Graphics g){
        super.paintComponent(g);
        // things you want to do here
    }
};

要承担更大的控制权,您可以忽略对

super.paintComponent(g);

但这样做需要你

必须遵守 opaque 属性,即如果此组件是不透明的,则必须将背景完全填充为不透明的颜色。如果您不尊重 opaque 属性,您可能会看到视觉伪影。

如Java API 文档中所述

于 2013-04-12T22:28:40.390 回答