更新:从您更新的问题我认为您实际上是在
JComponent.setBorder之后,示例屏幕截图:
码:
public static void main(String[] args) {
JTree tree = new JTree();
tree.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
JFrame frame = new JFrame("Test");
frame.add(new JScrollPane(tree));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
码:
public static void main(String[] args) {
JScrollPane scroll = new JScrollPane(new JTree());
scroll.setViewportBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
JFrame frame = new JFrame("Test");
frame.add(scroll);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}