Class ComponentBorder

  • All Implemented Interfaces:
    javax.swing.border.Border

    public class ComponentBorder
    extends java.lang.Object
    implements javax.swing.border.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 componet such that the insets of the Border will reserve space for the child component to be painted without affecting the parent component. From: http://tips4java.wordpress.com/2009/09/27/component-border/
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  ComponentBorder.Edge  
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static float CENTER  
      static float LEADING  
      static float TRAILING  
    • Constructor Summary

      Constructors 
      Constructor Description
      ComponentBorder​(javax.swing.JComponent component)
      Convenience constructor that uses the default edge (Edge.RIGHT) and alignment (CENTER).
      ComponentBorder​(javax.swing.JComponent component, ComponentBorder.Edge edge)
      Convenience constructor that uses the default alignment (CENTER).
      ComponentBorder​(javax.swing.JComponent component, ComponentBorder.Edge edge, float alignment)
      Main constructor to create a ComponentBorder.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      float getAlignment()
      Get the component alignment along the Border Edge
      java.awt.Insets getBorderInsets​(java.awt.Component c)  
      ComponentBorder.Edge getEdge()
      Get the Edge the component is positioned along
      int getGap()
      Get the gap between the border component and the parent component
      void install​(javax.swing.JComponent parent)  
      boolean isAdjustInsets()  
      boolean isBorderOpaque()  
      void paintBorder​(java.awt.Component c, java.awt.Graphics g, int x, int y, int width, int height)
      In this case a real component is to be painted.
      void setAdjustInsets​(boolean adjustInsets)  
      void setAlignment​(float alignment)
      Set the component alignment along the Border Edge
      void setEdge​(ComponentBorder.Edge edge)
      Set the Edge the component is positioned along
      void setGap​(int gap)
      Set the gap between the border component and the parent component
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ComponentBorder

        public ComponentBorder​(javax.swing.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​(javax.swing.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​(javax.swing.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 Detail

      • 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 final 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 final 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 java.awt.Insets getBorderInsets​(java.awt.Component c)
        Specified by:
        getBorderInsets in interface javax.swing.border.Border
      • isBorderOpaque

        public boolean isBorderOpaque()
        Specified by:
        isBorderOpaque in interface javax.swing.border.Border
      • paintBorder

        public void paintBorder​(java.awt.Component c,
                                java.awt.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 javax.swing.border.Border
      • install

        public void install​(javax.swing.JComponent parent)