rphello101
rphello101

Reputation: 1771

Why is my border overlapping my JTable?

I am trying to put a border around my JTable for my health tracking program, but the border is overlapping the table:

enter image description here

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

Answers (1)

alex2410
alex2410

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.

enter image description here

Upvotes: 2

Related Questions