简体   繁体   中英

how to get rid of visual effect when disabling buttons in java

When I'm setting the button to be disabled using this:

jButton.setEnabled(false);

then there is this visual effect visible on the second element ->

How can I disable the button, but keep the the look of the first element?

how to get rid of visual effect when disabling buttons

Companies spend millions of dollars to develop a UI can is common and can be used by all users.

How is the user suppose to know that the button is disabled if there is no visual indication?

Anyway, (rant finished) you can manually set the disabled icon:

button.setDisabledIcon( button.getIcon());

If you also happen to have text on the button the text will still be disabled so instead of a disabled icon you can use a custom ButtonModel:

button.setModel( new DefaultButtonModel()
{
    @Override
    public boolean isArmed()
    {
        return false;
    }

    @Override
    public boolean isPressed()
    {
        return false;
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM