A TextArea is ideal for presenting tabular results from an applet or application. It provides Scrollbars automatically when the text exceeds the available screen space. But despite careful use of spaces to align the entries in each column, you will find that cut and paste into a spreadsheet typically places an entire row into each cell. The solution is to place tab characters between the entries, a simple process to automate:
import java.awt.*;public class TabbedArea extends TextArea {// Constructor public TabbedArea() { super(); }// Append method public void append(String entry) { if (entry.endsWith("
")) super.append(entry); else super.append(entry + " "); }}
You can add other contructors to match those of the TextArea class if needed. But if the above constructor, with no arguments, is the only one, it is not strictly necessary to define it. The TabbedArea’s append method assumes that you will build a table of text one entry at a time.