Другая альтернатива - поместить текст в JTextArea
и поместить в JScrollPane
.
Е.Г.
Код
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class ExpandingText {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
final String s =
"The quick brown fox jumped over the lazy dog. ";
final JTextArea textArea = new JTextArea(s,5,30);
textArea.setWrapStyleWord(true);
textArea.setLineWrap(true);
textArea.setEditable(false);
textArea.setFocusable(false);
JButton button = new JButton("Add Text");
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae) {
textArea.append(s);
}
});
JPanel panel = new JPanel(new BorderLayout(3,3));
panel.add(button, BorderLayout.NORTH);
panel.add(new JScrollPane(textArea), BorderLayout.CENTER);
JOptionPane.showMessageDialog(null, panel);
}
});
}
}