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.
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));
