i am developing a GUI using Java Swing. but i got stuck here.
Is it not possible to add text to the single “JTextArea” dynamically?
Ex:
class Sample extends JFrame{
public static void fn(int n) {
JFrame f = new JFrame();
JTextArea ta = new JTextArea();
f.add(ta);
f.setVisible(true);
for(int i=1;i<=n;i++){
//some processing is done
ta.setText(" step is done");
// some other stuffs
}
}
}
this is just part of my source code. My problem here is , in this code for each iteration of the “for loop” i am getting a new frame with the text ” step is done”. but instead i want it to be displayed on a single frame ‘n; times.
setText()method sets the text, not appends its. You’ll have to do that manually:EDIT:
My bad, I didn’t use Swing for a while and simply forgot about such a basic thing as
append(). You should accept @Hovercraft Full Of Eels answer as it’s a correct and much better one.