作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 JEditorPane,需要附加一个滚动条。我试图将 JEditorPane 嵌套在 JScrollPane 中。这里我提供一个SSCCE。
import java.awt.Dimension;
import javax.swing.*;
public class Test{
public static void main(String[] args){
JFrame frame = new JFrame();
//Generate filler text to illustrate the lack of a scrollbar
String fillerText = "";
for(int i = 0; i < 500; i++){
fillerText += "The quick brown fox jumped over the lazy dog. ";
}
//Initialize JEditorPane
JEditorPane viewer = new JEditorPane();
viewer.setPreferredSize(new Dimension(500, 600));
viewer.setText(fillerText);
//Initialize JScrollPane
JScrollPane scroll = new JScrollPane(viewer);
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
//Add viewer to the frame
frame.add(viewer);
//Make frame visible
frame.pack();
frame.setVisible(true);
}
}
为什么滚动条不可见,如何才能使滚动条可见?
最佳答案
接下来的问题:您将 JEditorPane
添加到 JFrame
而不是 JScrollPane
中。当您需要使用 JScrollPane
时,您可以将组件添加到该 View 并将 JScrollPane
添加到容器。
将 frame.add(viewer);
替换为 frame.add(scroll);
就可以了。
关于java - JScrollPane 内的 JViewerPane,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20536919/
我有一个 JEditorPane,需要附加一个滚动条。我试图将 JEditorPane 嵌套在 JScrollPane 中。这里我提供一个SSCCE。 import java.awt.Dimensio
我是一名优秀的程序员,十分优秀!