devxlogo

Enable Pasting to Spreadsheets

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.

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  Five Early Architecture Decisions That Quietly Get Expensive

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.