Interface StylableComponent

All Known Implementing Classes:
JBox, JGlassPane, JIcon, JScrollPanels, JScrollPanels.EntryPanel, JSplitButton, UI.Box, UI.Button, UI.CheckBox, UI.CheckBoxMenuItem, UI.ComboBox, UI.Component, UI.EditorPane, UI.FormattedTextField, UI.Label, UI.List, UI.Menu, UI.MenuBar, UI.MenuItem, UI.Panel, UI.PasswordField, UI.PopupMenu, UI.ProgressBar, UI.RadioButton, UI.RadioButtonMenuItem, UI.ScrollPane, UI.Slider, UI.Spinner, UI.SplitButton, UI.SplitPane, UI.TabbedPane, UI.Table, UI.TableHeader, UI.TextArea, UI.TextField, UI.TextPane, UI.ToggleButton, UI.ToolBar, UI.ToolTip, UI.Tree

public interface StylableComponent
Implementations of this interface are SwingTree native components which enjoy the full support of the style API. Regular Swing components can be styled on most layers but not all. The UI.Layer.BACKGROUND and UI.Layer.FOREGROUND layers are not supported for some components for which SwingTree tries to install a custom UI delegate.
This however is prone to side effects and can cause issues with third party look and feels.
For full support of the style API for your custom components you should implement this interface.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    This method is expected to be implemented as follows within a component extension which ought to be made compatible with SwingTree.
    default void
    This default method is not intended to be overridden by client code! It delegates the painting to the library internal ComponentExtension.
    void
    This method is expected to be implemented as follows:
    default void
    This default method is not intended to be overridden by client code! It delegates the painting to the library internal ComponentExtension.
    void
    Certain style configurations require SwingTree to install a custom UI delegate.
  • Method Details

    • setUISilently

      void setUISilently(ComponentUI ui)
      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
        }
        
      Parameters:
      ui - the UI delegate to set for the component without triggering side effects.
    • paint

      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));
            }
        
      Parameters:
      g - the graphics context to paint on, obtained from the component's JComponent.paint(Graphics) method.
    • paintChildren

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

      default void paintBackground(Graphics g, Consumer<Graphics> superPaint)
      This default method is not intended to be overridden by client code! It delegates the painting to the library internal ComponentExtension.
      Parameters:
      g - The graphics context to paint on.
      superPaint - The super.paint() method to call.
    • paintForeground

      default void paintForeground(Graphics g, Consumer<Graphics> superPaint)
      This default method is not intended to be overridden by client code! It delegates the painting to the library internal ComponentExtension.
      Parameters:
      g - The graphics context to paint on.
      superPaint - The super.paintChildren() method to call.