Application Techniques



Using the JTextArea Control

How to use the Swing text area control on a form.

About this technique

Details

Category

Java Client Techniques> Version 3 Swing-based controls

Description

You'll learn about:

You can run this technique code from:

NOTE   First make sure that database is running on your localhost SilverStream Server

Related reading

See the chapter on the Form Designer in the Tools Guide

Getting and setting a string in a text area   Top of page

The following code uses getText() to get the text from the text area taEnterText, and then uses setText() to place the text in taTextArea.

This code is in the actionPerformed event of btnSetText.

  // Get the text from the data entry text area and put it in  
  // the target text area, replacing any text already there 
  taTextArea.setText(taEnterText.getText()); 
   
  // Clear the data entry text area 
  taEnterText.setText(""); 

Notes about the code

Appending a string to a string in a text area   Top of page

This code uses getText() to get the text entered in the text field taEnterText, and then uses appendText() to append this string to another string in taTextArea.

This code is in the actionPerformed event of btnAppend.

  // Get the text from the data entry text area and append it 
  // to the text already in the target text area 
  taTextArea.append(taEnterText.getText()); 
   
  // Clear the data entry text area 
  taEnterText.setText(""); 

Notes about the code

Getting and displaying selected text in a dialog box   Top of page

The following code uses the getSelectedText() method to get text the user selected (highlighted) in the text area taTextArea. It then uses the agDialog.showMessage() method to display the selected text in a standard message box.

This code is in the actionPerformed event of btnSelectedText.

  // Get the selected text from the target text area 
  agDialog.showMessage("taTextArea Selected Text", 
   taTextArea.getSelectedText()); 

Notes about the code






Copyright © 2000, SilverStream Software, Inc. All rights reserved.