Reputation: 1771
I am trying to put a border around my JTable for my health tracking program, but the border is overlapping the table:
Border border = BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED),"Summary");
Object[][] statsObj;
String[] headers = {"","","","","",""}
JTable statsT = new JTable(statsObj, headers);
statsT.setBackground(null);
statsT.setShowGrid(false);
statsT.setBorder(border);
Any idea what is going on or how I can fix the problem?
Upvotes: 1
Views: 207
Reputation: 10994
You can fix that with wrapping your JTable
with help of JScrollPane
or JPanel
and setting Border
to that component. For example:
JScrollPane pane = new JScrollPane(statsT);
pane.setBorder(border);
if you needn't to show table header add statsT.setTableHeader(null);
Or with JPanel
:
JPanel p = new JPanel(new BorderLayout());
p.add(statsT);
p.setBorder(border);
But, it is better to use JScrollPane
.
Upvotes: 2