简体   繁体   中英

how to change JRadioButton selectionBall's color?

how to change JRadioButton selectionBall's color? we should use BasicRadioButtonUI? how should we do that? or we should change the radioButton's selectedIcon ?

or we should change the radioButton's selectedIcon ?

  • there isn't radioButton's selectedIcon , everything is done in paintIcon (with two states)

  • you can to override paintIcon in BasicRadioButtonUI

EDIT

there are two ways,

depends of Java version and used L&F, have to test

@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
    int offset = (c.getHeight() - iconSide) / 2;
    g.setColor(Color.red);
    g.fillOval(x + offset, y + offset, dotDia, dotDia);                
}

// or

@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
    int offset = (c.getHeight() - iconSide) / 2;
    g.setColor(Color.red);
    g.fillRoundRect(x + offset, y + offset, dotDia, dotDia, arc, arc);
}

or (dirty way) to setIcon (prepared) in UIManager , required to set revalidate() and repaint() for all mouse or key events

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