Java Reference
In-Depth Information
String outputString = "";
for (int i = 0; i < 100; i++) {
outputString += "The quick brown fox jumped over the lazy dog. ";
}
JTextArea textDisplay = new JTextArea(20, 60);
textDisplay.setLineWrap(true);
theFrame.add(textDisplay);
theFrame.pack();
textDisplay.setText(outputString);
theFrame.setVisible(true);
}
}
Figure 8-20. Display when attempting to show too much text
In most cases, the simplest solution to this problem is changing the line
theFrame.add(textDisplay);
to read
theFrame.add(new JScrollPane(textDisplay));
The results of this change are shown in Figure 8-21.
Search WWH ::




Custom Search