i appending text to text area for every sec i wanted to overwrite or clear the old text and i want write new data for every one sec how to do this in java?
Thanks raksha
i appending text to text area for every sec i wanted to overwrite or clear the old text and i want write new data for every one sec how to do this in java?
Thanks raksha
I guess you are talking about a Swing JTextArea
.
You can just call setText(...)
on it to replace the text:
JTextArea textArea = ...;
textArea.setText("Hello World");
To do something periodically you need some thread, but be aware to use SwingWorker. If not your GUI may freeze.
final JTextArea ta = frame.getjTextArea1();
SwingWorker worker = new SwingWorker() {
@Override
protected Object doInBackground() throws Exception {
while (true) {
ta.setText("");
ta.setText(new Date().toString());
Thread.sleep(1000);
}
}
};
worker.execute();