我有这个类作为我的问题的一个例子。滚动窗格不滚动,我看不出一个很好的理由:
import java.awt.Dimension;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class DoesNotScroll{
public static void main(String[] args){
String str = "this\n\nshould\n\n\n\nscroll\n\n\nthis is the bottom";
message("test", str, JOptionPane.INFORMATION_MESSAGE);
}
public final static void message(String title, String message, int messageType){
JTextArea messageArea = new JTextArea();
messageArea.setMinimumSize(new Dimension(300, 100));
messageArea.setMaximumSize(new Dimension(300, 100));
messageArea.setPreferredSize(new Dimension(300, 100));
messageArea.setEditable(false);
JScrollPane scroller = new JScrollPane(messageArea);
scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
messageArea.setText(message);
messageArea.revalidate();
messageArea.repaint();
JOptionPane.showMessageDialog(null, scroller, title, messageType);
}
}
任何帮助表示赞赏,
-C