Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Intermediate
Jul 23, 1998

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("\n"))
            super.append(entry);
        else
            super.append(entry + "\t");
    }
}

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.
Tom Yarker
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date