Class JBox

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, StylableComponent
Direct Known Subclasses:
JScrollPanels.EntryPanel, UI.Box

public class JBox extends JComponent implements Accessible, StylableComponent
JBox is a generic lightweight container similar to javax.swing.JPanel, but with 2 important differences:
  • The JBox is transparent by default, meaning that it does not paint its background if it is not explicitly set through the style API.
  • It does not have any insets by default.
Please note that the JBox type is in no way related to the BoxLayout! The term box is referring to the purpose of this component, which is to tightly store and wrap other sub-components seamlessly...
See Also:
  • Constructor Details

    • JBox

      public JBox(LayoutManager layout, boolean isDoubleBuffered)
      Creates a new JBox with the specified layout manager and buffering strategy.
      Parameters:
      layout - the LayoutManager to use
      isDoubleBuffered - a boolean, true for double-buffering, which uses additional memory space to achieve fast, flicker-free updates
    • JBox

      public JBox(LayoutManager layout)
      Create a new buffered JBox with the specified layout manager
      Parameters:
      layout - the LayoutManager to use
    • JBox

      public JBox(boolean isDoubleBuffered)
      Creates a new JBox with the specified buffering strategy qnd a default MigLayout instance configured to be without insets and gaps between components. If isDoubleBuffered is true, the JBox will use a double buffer.
      Parameters:
      isDoubleBuffered - a boolean, true for double-buffering, which uses additional memory space to achieve fast, flicker-free updates
    • JBox

      public JBox()
      Creates a new JBox with a double buffer and a flow layout.
  • 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()
      Resets the UI property with a value from the current look and feel.
      Overrides:
      updateUI in class JComponent
      See Also:
    • getUI

      public PanelUI getUI()
      Returns the look and feel (L&F) object that renders this component.
      Overrides:
      getUI in class JComponent
      Returns:
      the PanelUI object that renders this component
    • setUI

      public void setUI(PanelUI ui)
      Sets the look and feel (L&F) object that renders this component.
      Parameters:
      ui - the PanelUI L&F object
      See Also:
    • getUIClassID

      public String getUIClassID()
      Returns a string that specifies the name of the L&F class that renders this component.
      Overrides:
      getUIClassID in class JComponent
      Returns:
      "PanelUI"
      See Also:
    • paramString

      protected String paramString()
      Returns a string representation of this JBox. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.
      Overrides:
      paramString in class JComponent
      Returns:
      a string representation of this JBox.
    • getAccessibleContext

      public AccessibleContext getAccessibleContext()
      Gets the AccessibleContext associated with this JBox. For the JBox, the AccessibleContext takes the form of an AccessibleJBox. A new AccessibleJBox instance is created if necessary.
      Specified by:
      getAccessibleContext in interface Accessible
      Overrides:
      getAccessibleContext in class Component
      Returns:
      an AccessibleJBox that serves as the AccessibleContext of this JBox