如何在Java Swing的JScrollPane中添加边框?

huangapple go评论70阅读模式
英文:

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));

huangapple
  • 本文由 发表于 2020年9月17日 23:48:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/63941721.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定