IconBorder implements Border, Serializable { public Insets getBorderInsets(Component c) { int horizontalInset = icon.getIconWidth() + (2 * padding); int iconPosition = bidiDecodeLeadingTrailing(c.getComponentOrientation(), this.iconPosition); if (iconPosition == SwingConstants.EAST) { return new Insets(0, 0, 0, horizontalInset); } return new Insets(0, horizontalInset, 0, 0); } IconBorder();  IconBorder(Icon validIcon);  IconBorder(Icon validIcon, int iconPosition);  IconBorder(Icon validIcon, int iconPosition, int padding); Insets getBorderInsets(Component c); void setIcon(Icon validIcon); boolean isBorderOpaque(); void paintBorder(Component c, Graphics g, int x, int y, int width,
        int height); int getPadding(); void setPadding(int padding); int getIconPosition(); void setIconPosition(int iconPosition); static final Icon EMPTY_ICON; }
@Test public void testSafeBorderMisbehavingDelegate() { JComponent comp = new JButton(); MisbehavingBorder delegate = new MisbehavingBorder(); assertNull("sanity", delegate.getBorderInsets(comp)); assertNull("sanity", delegate.getBorderInsets(comp, null)); SafeBorder border = new SafeBorder(delegate); assertNotNull(border.getBorderInsets(comp)); assertNotNull(border.getBorderInsets(comp, null)); }
@Test public void testSafeBorderBehavingDelegate() { JComponent comp = new JButton(); AbstractBorder delegate = new BevelBorder(BevelBorder.LOWERED); SafeBorder border = new SafeBorder(delegate); assertNotNull(border.getBorderInsets(comp)); assertNotNull(border.getBorderInsets(comp, null)); }
@Test public void testIconBorderNullIcon() { IconBorder border = new IconBorder(); JLabel label = new JLabel("dummy"); border.getBorderInsets(label); }
@Test public void testDefaultPadding() { Icon icon = new ColumnControlIcon(); IconBorder border = new IconBorder(icon, SwingConstants.WEST); JLabel label = new JLabel("dummy"); label.setBorder(border); Insets insets = border.getBorderInsets(label); assertEquals(insets.left, icon.getIconWidth() + 8); }