Java Utililty Methods Swing Border

List of utility methods to do Swing Border

Description

The list of methods to do Swing Border are organized into topic(s).

Method

voidaddBorder(JComponent c, Border b)
add Border
Border cb = c.getBorder();
Border nb = cb == null ? b : new CompoundBorder(cb, b);
c.setBorder(nb);
voidaddBorder(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);
JComponentaddOuterBorder(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;
...
StringclipText(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;
...
booleancompareTabOrder(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();
...
Bordercopy(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() {
...
BordercreateCompoundBorder(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;
voidcreateDebugBorder(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));
BordercreateFormSectionBorder(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));
JScrollPanecreateJScrollPane(Component component, Rectangle bounds, Color backgroundColor, boolean noBorder, boolean visible)
Creates a new JScrollPane object with the given properties.
JScrollPane pane = new JScrollPane();
if (bounds != null) {
    pane.setBounds(bounds);
pane.setBackground(backgroundColor);
pane.setViewportView(component);
if (noBorder) {
    pane.setBorder(null);
...