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

voidpaintBorderDebugInfo(final Graphics g, final JComponent c)
Paints border debug information.
paintBorderDebugInfo(g, c, Color.RED);
voidremovePopupBorder(final Container c)
remove Popup Border
EventQueue.invokeLater(() -> {
    Container p = c;
    while (p != null) {
        if (p instanceof JComponent) {
            ((JComponent) p).setBorder(null);
        p = p.getParent();
});
voidrepaintBorder(JComponent component)
repaint Border
JComponent c = component;
Border border = null;
Container container = component.getParent();
if (container instanceof JViewport) {
    c = (JComponent) container.getParent();
    if (c != null) {
        border = c.getBorder();
if (border == null) {
    border = component.getBorder();
    c = component;
if (border != null && c != null) {
    int w = c.getWidth();
    int h = c.getHeight();
    Insets insets = c.getInsets();
    c.repaint(0, 0, w, insets.top);
    c.repaint(0, insets.top, insets.left, h - insets.bottom - insets.top);
    c.repaint(0, h - insets.bottom, w, insets.bottom);
    c.repaint(w - insets.right, insets.top, insets.right, h - insets.bottom - insets.top);
voidrepaintBorder(JComponent component)
repaint Border
JComponent c = component;
Border border = null;
Container container = component.getParent();
if (container instanceof JViewport) {
    c = (JComponent) container.getParent();
    if (c != null) {
        border = c.getBorder();
if (border == null) {
    border = component.getBorder();
    c = component;
if (border != null && c != null) {
    int w = c.getWidth();
    int h = c.getHeight();
    Insets insets = c.getInsets();
    c.repaint(0, 0, w, insets.top);
    c.repaint(0, 0, insets.left, h);
    c.repaint(0, h - insets.bottom, w, insets.bottom);
    c.repaint(w - insets.right, 0, insets.right, h);
voidsetBorder(Border b, JComponent... components)
Set the border of the given components.
for (JComponent c : components) {
    c.setBorder(b);
JComponentsetBorder(JComponent comp, boolean setBorder, Color col)
set Border
Border redline = BorderFactory.createLineBorder(col);
Border raisedbevel = BorderFactory.createRaisedBevelBorder();
Border loweredbevel = BorderFactory.createLoweredBevelBorder();
Border compound1 = BorderFactory.createCompoundBorder(raisedbevel, loweredbevel);
Border compound2 = BorderFactory.createCompoundBorder(redline, compound1);
if (setBorder)
    comp.setBorder(compound2);
else
...
voidsetBorder(JComponent comp, Border border)
Sets the border in a given component.
if (comp.getBorder() != null) {
    comp.setBorder(BorderFactory.createCompoundBorder(comp.getBorder(), border));
} else {
    comp.setBorder(border);
voidsetDebugBorder(final JComponent component)
set Debug Border
component.setBorder(BorderFactory.createDashedBorder(debugBorderPaint));
voidsetDefaultComponentsTabOrder(Vector v)
set Default Components Tab Order
Object tmp;
int i, j, c;
for (i = 0, c = v.size(); i < c; i++) {
    for (j = i; j < c; j++) {
        if (i == j)
            continue;
        if (compareTabOrder((Component) v.elementAt(j), (Component) v.elementAt(i))) {
            tmp = v.elementAt(i);
...
voidsetViewportBorder(JScrollPane scrollPane, int vertical, int horizontal)
set Viewport Border
scrollPane.setViewportBorder(BorderFactory.createMatteBorder(vertical, horizontal, vertical, horizontal,
        scrollPane.getViewport().getView().getBackground()));