Class ComponentBorder

java.lang.Object
com.jsql.view.swing.ui.ComponentBorder
All Implemented Interfaces:
Border

public class ComponentBorder extends Object implements Border
The ComponentBorder class allows you to place a real component in the space reserved for painting the Border of a component. This class takes advantage of the knowledge that all Swing components are also Containers. By default, the layout manager is null, so we should be able to place a child component anywhere in the parent component. In order to prevent the child component from painting over top of the parent component a Border is added to the parent component such that the insets of the Border will reserve space for the child component to be painted without affecting the parent component.
  • Field Details

  • Constructor Details

    • ComponentBorder

      public ComponentBorder(JComponent component)
      Convenience constructor that uses the default edge (Edge.RIGHT) and alignment (CENTER).
      Parameters:
      component - the component to be added in the Border area
    • ComponentBorder

      public ComponentBorder(JComponent component, int addX, int addY)
    • ComponentBorder

      public ComponentBorder(JComponent component, ComponentBorder.Edge edge)
      Convenience constructor that uses the default alignment (CENTER).
      Parameters:
      component - the component to be added in the Border area
      edge - a valid Edge enum of TOP, LEFT, BOTTOM, RIGHT
    • ComponentBorder

      public ComponentBorder(JComponent component, ComponentBorder.Edge edge, float alignment)
      Main constructor to create a ComponentBorder.
      Parameters:
      component - the component to be added in the Border area
      edge - a valid Edge enum of TOP, LEFT, BOTTOM, RIGHT
      alignment - the alignment of the component along the specified Edge. Must be in the range 0 - 1.0.
  • Method Details

    • isAdjustInsets

      public boolean isAdjustInsets()
    • setAdjustInsets

      public void setAdjustInsets(boolean adjustInsets)
    • getAlignment

      public float getAlignment()
      Get the component alignment along the Border Edge.
      Returns:
      the alignment
    • setAlignment

      public void setAlignment(float alignment)
      Set the component alignment along the Border Edge.
      Parameters:
      alignment - a value in the range 0 - 1.0. Standard values would be CENTER (default), LEFT and RIGHT.
    • getEdge

      public ComponentBorder.Edge getEdge()
      Get the Edge the component is positioned along.
      Returns:
      the Edge
    • setEdge

      public void setEdge(ComponentBorder.Edge edge)
      Set the Edge the component is positioned along.
      Parameters:
      edge - the Edge the component is position on.
    • getGap

      public int getGap()
      Get the gap between the border component and the parent component.
      Returns:
      the gap in pixels.
    • setGap

      public void setGap(int gap)
      Set the gap between the border component and the parent component.
      Parameters:
      gap - the gap in pixels (default is 5)
    • getBorderInsets

      public Insets getBorderInsets(Component c)
      Specified by:
      getBorderInsets in interface Border
    • isBorderOpaque

      public boolean isBorderOpaque()
      Specified by:
      isBorderOpaque in interface Border
    • paintBorder

      public void paintBorder(Component c, Graphics g, int x, int y, int width, int height)
      In this case a real component is to be painted. Setting the location of the component will cause it to be painted at that location.
      Specified by:
      paintBorder in interface Border
    • install

      public void install(JComponent parent)
      Install this Border on the specified component by replacing the existing Border with a CompoundBorder containing the original Border and our ComponentBorder This method should only be invoked once all the properties of this class have been set. Installing the Border more than once will cause unpredictable results.