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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top