我在JTable
中有JScrollPane
。
JTable table = new JTable(data, columnNames);
JScrollPane scroll = new JScrollPane();
scroll.setViewportView(table);
一切都很顺利,但如果我需要在Scrollpanel和桌子之间留出更多空间?我怎样才能做到这一点?例如:如果我们使用HTML/CSS
标记,则在<div>
中,我们使用“填充”方法。我需要这样的东西。
答案 0 :(得分:4)
你可以做到
scroll.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
答案 1 :(得分:2)
另一种解决方案是
setBorder(BorderFactory.createCompoundBorder(new EmptyBorder(10, 10, 10, 10), new EtchedBorder()));
它也不会删除组件周围的黑线,这也是ScrollPanel内的。