Package com.jsql.view.swing.ui
Class ComponentBorder
java.lang.Object
com.jsql.view.swing.ui.ComponentBorder
- All Implemented Interfaces:
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.
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
ConstructorDescriptionComponentBorder
(JComponent component) Convenience constructor that uses the default edge (Edge.RIGHT) and alignment (CENTER).ComponentBorder
(JComponent component, int addX, int addY) ComponentBorder
(JComponent component, ComponentBorder.Edge edge) Convenience constructor that uses the default alignment (CENTER).ComponentBorder
(JComponent component, ComponentBorder.Edge edge, float alignment) Main constructor to create a ComponentBorder. -
Method Summary
Modifier and TypeMethodDescriptionfloat
Get the component alignment along the Border 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
(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.boolean
boolean
void
paintBorder
(Component c, 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.
-
Field Details
-
LEADING
public static final float LEADING- See Also:
-
CENTER
public static final float CENTER- See Also:
-
TRAILING
public static final float TRAILING- See Also:
-
-
Constructor Details
-
ComponentBorder
Convenience constructor that uses the default edge (Edge.RIGHT) and alignment (CENTER).- Parameters:
component
- the component to be added in the Border area
-
ComponentBorder
-
ComponentBorder
Convenience constructor that uses the default alignment (CENTER).- Parameters:
component
- the component to be added in the Border areaedge
- a valid Edge enum of TOP, LEFT, BOTTOM, RIGHT
-
ComponentBorder
Main constructor to create a ComponentBorder.- Parameters:
component
- the component to be added in the Border areaedge
- a valid Edge enum of TOP, LEFT, BOTTOM, RIGHTalignment
- 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
Get the Edge the component is positioned along.- Returns:
- the Edge
-
setEdge
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
- Specified by:
getBorderInsets
in interfaceBorder
-
isBorderOpaque
public boolean isBorderOpaque()- Specified by:
isBorderOpaque
in interfaceBorder
-
paintBorder
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 interfaceBorder
-
install
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.
-