Class NullRadioButton

All Implemented Interfaces:
ImageObserver, ItemSelectable, MenuContainer, Serializable, Accessible, SwingConstants

public class NullRadioButton extends JRadioButton
This is part of the null-components. A null component doesn't have foreground, background or font value set. In the other words, the foreground, background and font value of null-component are null. But this doesn't mean getBackground(), getForeground() or getFont() will return null. According to Component.getBackground(), Component.getForeground() and Component.getFont(), if the value is null, it will get the value from its parent. In the other words, if you add a null-component to JPanel, you can use JPanel to control the background, foreground and font of this null-component. The feature is very helpful if you want to make sure all components in a JPanel has the same background, foreground or font.

Even in null-components, you can still change the foreground, background or font value if you do want. However, you'll have to use a font which is not an instance of FontUIResource or a color which is not an instance of ColorUIResource.

We creates a few null-components. It doesn't cover all components. You can always create your own. All you need to do is this


 public class NullXxxComponent extends XxxComponent {
     // invoke clearAttribute() in all the constructors
 

public void setFont(Font font) { if (font instanceof FontUIResource) { return; } super.setFont(font); }

public void setBackground(Color bg) { if (bg instanceof ColorUIResource) { return; } super.setBackground(bg); }

public void setForeground(Color fg) { if (fg instanceof ColorUIResource) { return; } super.setForeground(fg); }

private void clearAttribute() { setFont(null); setBackground(null); // do not do this for JButton since JButton always paints button // content background. So it'd better to leave the foreground alone setForeground(null); } }

See Also:
  • Constructor Details

    • NullRadioButton

      public NullRadioButton()
    • NullRadioButton

      public NullRadioButton(Icon icon)
    • NullRadioButton

      public NullRadioButton(Action a)
    • NullRadioButton

      public NullRadioButton(Icon icon, boolean selected)
    • NullRadioButton

      public NullRadioButton(String text)
    • NullRadioButton

      public NullRadioButton(String text, boolean selected)
    • NullRadioButton

      public NullRadioButton(String text, Icon icon)
    • NullRadioButton

      public NullRadioButton(String text, Icon icon, boolean selected)
  • Method Details