通过JScrollPane填充JTable

时间:2013-08-08 13:55:34

标签: java swing jscrollpane

我在JTable中有JScrollPane

JTable table = new JTable(data, columnNames);
JScrollPane scroll = new JScrollPane();
scroll.setViewportView(table);

一切都很顺利,但如果我需要在Scrollpanel和桌子之间留出更多空间?我怎样才能做到这一点?例如:如果我们使用HTML/CSS标记,则在<div>中,我们使用“填充”方法。我需要这样的东西。

2 个答案:

答案 0 :(得分:4)

你可以做到

scroll.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

答案 1 :(得分:2)

另一种解决方案是

setBorder(BorderFactory.createCompoundBorder(new EmptyBorder(10, 10, 10, 10), new EtchedBorder()));

它也不会删除组件周围的黑线,这也是ScrollPanel内的。