为什么我的边框与我的JTable重叠?

时间:2014-03-05 22:31:11

标签: java swing jtable border

我正在尝试为我的健康追踪程序设置JTable边框,但边框与表重叠:

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

知道发生了什么或我如何解决问题?

1 个答案:

答案 0 :(得分:2)

您可以在JTableJScrollPane的帮助下将JPanel包裹起来并将Border设置为该组件,从而解决此问题。例如:

JScrollPane pane = new JScrollPane(statsT);
pane.setBorder(border);

如果您不需要显示表格标题,请添加statsT.setTableHeader(null);

JPanel

JPanel p = new JPanel(new BorderLayout());
p.add(statsT);
p.setBorder(border);

但是,最好使用JScrollPane

enter image description here