[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

Switching text in TextArea.

hi!

I am trying to fine convenient way to switch text(from one sentence to another sentence) in TextArea when button is clicked.
Any suggestions will be helpful...

Thanks,


0
dkim18
Asked:
dkim18
  • 2
  • 2
2 Solutions
 
WebstormCommented:
Hi dkim18,

To change the text you can use setText:

    TextArea ta=new TextArea("first text");
    Button b=new Button("OK");

    ...
    b.addActionListener(
        new ActionListener(){
            public void actionPerformed(ActionEvent ev)
            {
                 // ta.getText();
                 ta.setText("second text");
            }
        }
    }

What do you mean by "to switch text" ? Can you give some examples ?

0
 
CEHJCommented:
You can keep your sentences in arrays:

final String[] SENTENCES = { "xxx", "yyy", "zzz" };
int sentenceIndex = 0;


public void actionPerformed(ActionEvent ev)
{
    ta.setText(SENTENCES[sentenceIndex++ % SENTENCES.length]);
}


0
 
CEHJCommented:
8-)
0
 
WebstormCommented:
:-)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now