0
我有一個JEditorPane,我需要附加一個滾動條。我試圖在JScrollPane中嵌套JEditorPane。我在這裏提供一個SSCCE。JScrollPane中的JViewerPane
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);
}
}
爲什麼沒有滾動條變得可見,以及如何讓其中一個可見?
完美地工作。我想我一定誤解了我正在閱讀的教程。謝謝。 – Benjamin