Class JIcon

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

public class JIcon extends JLabel implements StylableComponent
A JLabel subclass specifically designed to display icons only. Although a JLabel already provides the ability to display icons, this class is useful for styling purposes, as it is possible to specifically target icons inside of StyleSheets.
See Also:
  • Constructor Details

    • JIcon

      public JIcon(String path)
    • JIcon

      public JIcon(IconDeclaration declaration)
    • JIcon

      public JIcon(Icon icon)
    • JIcon

      public JIcon(Icon icon, String text, int horizontalAlignment)
    • JIcon

      public JIcon(String text, int horizontalAlignment)
    • JIcon

      public JIcon(String path, String text)
    • JIcon

      public JIcon()
  • Method Details

    • paint

      public void paint(Graphics g)
      This method is expected to be implemented as follows within a component extension which ought to be made compatible with SwingTree.
            @Override
            public void paint(Graphics g){
                paintBackground(g, ()->super.paint(g));
            }
        
      Specified by:
      paint in interface StylableComponent
      Overrides:
      paint in class JComponent
      Parameters:
      g - the graphics context to paint on, obtained from the component's JComponent.paint(Graphics) method.
    • paintChildren

      public void paintChildren(Graphics g)
      This method is expected to be implemented as follows:
            @Override
            public void paintChildren(Graphics g){
                paintForeground(g, ()->super.paintChildren(g));
            }
        
      Specified by:
      paintChildren in interface StylableComponent
      Overrides:
      paintChildren in class JComponent
      Parameters:
      g - the graphics context to paint on, obtained from the component's JComponent::paintChildren(Graphics) method.
    • setUISilently

      public void setUISilently(ComponentUI ui)
      Description copied from interface: StylableComponent
      Certain style configurations require SwingTree to install a custom UI delegate. This method is used to set the UI delegate for the component but without triggering side effects like the former UI being uninstalled (which itself can cause a lot of undesired side effects).

      This method is not intended to be called by client code! It exists for internal use only and unfortunately cannot be protected or private due to the nature of the Swing API.

      The implementation of this method is expected to look like this:

        @Override
        public void setUISilently(ComponentUI ui){
            this.ui = ui; // no side effects
        }
        
      Specified by:
      setUISilently in interface StylableComponent
      Parameters:
      ui - the UI delegate to set for the component without triggering side effects.
    • updateUI

      public void updateUI()
      Overrides:
      updateUI in class JLabel