通过 JScrollPane 填充 JTable

gre*_*rep 3 java swing jscrollpane

JTableJScrollPane.

JTable table = new JTable(data, columnNames);
JScrollPane scroll = new JScrollPane();
scroll.setViewportView(table);
Run Code Online (Sandbox Code Playgroud)

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

Rei*_*eus 5

你可以做

scroll.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
Run Code Online (Sandbox Code Playgroud)