Increase the thickness of the border of the focused area in swing

211 Views Asked by At

I have a problem with Java Swing and the LAF. I am using JGoodies and I tried to increase the thickness of the border of the focused area. I tried it via the UIDefault but there is no such option. example of the Border Can you give me a hint how to set the border?

I saw this post: Change the color of the Java Swing Component Focus indicator but there is no solution to my problem.

example

1

There are 1 best solutions below

0
vincenzopalazzo On

This style depends on the L&F, if it supports the Table.border propriety or the Table.scrollPaneBorder.

In some cases, this property Table.scrollPaneBorder is enough but there aren't rules to have the table wrapped inside the scroll pane wrap table. In other words, you can have a table without a scroll panel.

if you have a table without scroll panel, the problem can be resolve from LookAndFeel, if your actual L&f doesn't have this support, the solutions are multiple, such as:

  • Use another l&f. such as Material-ui-swing, the table.border is under the developing branch, you can compile the source.
  • Develop a personal TableUI to set the border inside the UI such as the point one
  • you can wrapper your table inside a scroll pane, but it should respect the L&f rules.

1. Implement the Table UI. (from material-ui-swing)

insert a Border inside the propriety Table.border, such as:

UiManager.put("Table.border", new BorderUIResources(YOUR_BORDER));

You need to wrap the border inside the BorderUIResource because, if you implement the switch L6f inside your APP, Swing doesn't remove the propriety without the UIResource interface.

public class MaterialTableUI extends BasicTableUI {


    public static ComponentUI createUI (JComponent c) {
        return new MaterialTableUI();
    }

    @Override
    public void installUI (JComponent c) {
        super.installUI (c);
        table.setBorder(UIManager.getBorder("Table.border"));
    }
}

This answer makes an overview of all possible solutions that exist if the table is unwrapped from the Scroll Pane. In fact the propriety Table.scrollPaneBorder should be work fine

Example with material-ui-swing

set border

UIManager.put("Table.border", BorderFactory.createLineBorder(MaterialColors.COSMO_BLACK, 5));

enter image description here