The list of methods to do Swing Border are organized into topic(s).
void
addBorder(JComponent component, Border border) add Border
if (component == null)
return;
if (component.getBorder() != null) {
component.setBorder(new CompoundBorder(border, component.getBorder()));
} else {
component.setBorder(border);
JComponent
addOuterBorder(JComponent c, Border out) add Outer Border
Border b;
Border in = c.getBorder();
if (in == null)
b = out;
else
b = BorderFactory.createCompoundBorder(out, in);
c.setBorder(b);
return c;
...
String
clipText(JComponent c, String val, int borderWidth) Clip a text.
FontMetrics fm;
String str;
Insets insets;
int i, size, width, totWidth;
fm = c.getFontMetrics(c.getFont());
insets = c.getInsets();
width = c.getWidth() - (insets.left + insets.right) - 2 * borderWidth;
totWidth = fm.stringWidth(CLIPPING) + 2 * borderWidth;
...
boolean
compareTabOrder(Component a, Component b) compare Tab Order
Rectangle bounds;
int ay, by;
int ax, bx;
if (a instanceof JComponent) {
ay = ((JComponent) a).getY();
ax = ((JComponent) a).getX();
} else {
bounds = a.getBounds();
...
Border
copy(final Border border) copy
return new Border() {
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
border.paintBorder(c, g, x, y, width, height);
public Insets getBorderInsets(Component c) {
return border.getBorderInsets(c);
public boolean isBorderOpaque() {
...
Border
createCompoundBorder(Border... borders) create Compound Border
Border border = null;
for (int i = 0; i < borders.length; i++) {
border = i == 0 ? borders[i] : BorderFactory.createCompoundBorder(border, borders[i]);
return border;
void
createDebugBorder(JComponent c, Color color) Useful debug function to place a colored, line border around a component for layout management debugging.
if (color == null) {
color = Color.BLACK;
c.setBorder(BorderFactory.createLineBorder(color));
Border
createFormSectionBorder(Color color, String title) Creates border to separate form sections
return createCompoundBorder(createEmptyBorder(5, 0, 0, 0),
createTitledBorder(createMatteBorder(1, 0, 0, 0, color), title));