0

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

  • What Border? Components like JCheckBox, don't have a Border. A JTextField has a single line Border. A JButton has a thicker Border. So each component has a Border that suits the component. So there is no one step solution that fits all components. I don't know why you would try to change the LAF. – camickr Aug 07 '20 at 13:09
  • What do you mean by _the focused area_? Do you mean the [`Component`](https://docs.oracle.com/javase/8/docs/api/java/awt/Component.html) that currently has the keyboard [focus](https://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html)? – Abra Aug 07 '20 at 13:13
  • e.g. if the table is focused it gets a blue selection border. i tried to add a picture in the original post but it doesn´t seemed to work. i will try to add the Screenshot again – Deficiency Aug 07 '20 at 14:15
  • Do you mean something like this image: https://imgur.com/giDIvnM – Abra Aug 07 '20 at 15:55
  • Yes exactly the blue boarder around the table. not the row selection – Deficiency Aug 10 '20 at 06:45

1 Answers1

0

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

vincenzopalazzo
  • 1,487
  • 2
  • 7
  • 35