英文:
How to add a border to a Java Swing JScrollPane?
问题
我尝试使用setBorder()
方法向JScrollPane添加边框,但没有成功。如何向JScrollPane添加边框呢?
英文:
I've tried adding a border to a JScrollPane using the setBorder()
method, but it didn't work. How can I add a border to a JScrollPane?
答案1
得分: 1
根据JScrollPane文档,您可以使用setViewportBorder在主视口周围添加边框。
scrollpane.setViewportBorder(BorderFactory.createLineBorder(Color.black));
或者您可以像这个Oracle教程中所述,使用setBorder在整个滚动窗格周围添加边框:
pane.setBorder(BorderFactory.createLineBorder(Color.black));
英文:
According to the JScrollPane documentation, you can use setViewportBorder to add a border around the main viewport.
scrollpane.setViewportBorder(BorderFactory.createLineBorder(Color.black));
Or you could add a border around the whole scroll pane using setBorder as outlined in this Oracle tutorial:
pane.setBorder(BorderFactory.createLineBorder(Color.black));
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论