Package org.rspeer.commons
Class DelegatingBorder
- java.lang.Object
-
- javax.swing.border.AbstractBorder
-
- org.rspeer.commons.DelegatingBorder
-
- All Implemented Interfaces:
Serializable,Border
public class DelegatingBorder extends AbstractBorder
A self-installing border that wraps another Border (e.g., TitledBorder) and overlays a real Swing component as a child inside the border. No explicit install() needed.Usage:
TitledBorder titled = BorderFactory.createTitledBorder("Dataset"); DelegatingBorder border = new DelegatingBorder( titled, () -> { JLabel sub = new JLabel("ⓘ"); sub.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); sub.setToolTipText("Click for details"); sub.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(sub), "Clicked!"); } }); return sub; }, DelegatingBorder.Anchor.SOUTH_EAST, new Insets(4,6,4,6) ); panel.setBorder(border);- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDelegatingBorder.Anchor
-
Constructor Summary
Constructors Constructor Description DelegatingBorder(Border delegate, Supplier<JComponent> childComponentFactory)DelegatingBorder(Border delegate, Supplier<JComponent> childComponentFactory, DelegatingBorder.Anchor anchor)DelegatingBorder(Border delegate, Supplier<JComponent> childComponentFactory, DelegatingBorder.Anchor anchor, Insets padding)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description InsetsgetBorderInsets(Component c)InsetsgetBorderInsets(Component c, Insets insets)booleanisBorderOpaque()voidpaintBorder(Component c, Graphics g, int x, int y, int w, int h)-
Methods inherited from class javax.swing.border.AbstractBorder
getBaseline, getBaselineResizeBehavior, getInteriorRectangle, getInteriorRectangle
-
-
-
-
Constructor Detail
-
DelegatingBorder
public DelegatingBorder(Border delegate, Supplier<JComponent> childComponentFactory, DelegatingBorder.Anchor anchor, Insets padding)
-
DelegatingBorder
public DelegatingBorder(Border delegate, Supplier<JComponent> childComponentFactory, DelegatingBorder.Anchor anchor)
-
DelegatingBorder
public DelegatingBorder(Border delegate, Supplier<JComponent> childComponentFactory)
-
-
Method Detail
-
paintBorder
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h)
- Specified by:
paintBorderin interfaceBorder- Overrides:
paintBorderin classAbstractBorder
-
getBorderInsets
public Insets getBorderInsets(Component c)
- Specified by:
getBorderInsetsin interfaceBorder- Overrides:
getBorderInsetsin classAbstractBorder
-
getBorderInsets
public Insets getBorderInsets(Component c, Insets insets)
- Overrides:
getBorderInsetsin classAbstractBorder
-
isBorderOpaque
public boolean isBorderOpaque()
- Specified by:
isBorderOpaquein interfaceBorder- Overrides:
isBorderOpaquein classAbstractBorder
-
-