Reputation: 11
I want to add data from JTextField
but if I pressed the process again, the data that I write is missing. Is there any solution for this code?
try{
txttujuan.removeAll();
int xxx=0;
String XNilai,Nilai;
for (xxx=0;xxx <jtable.getRowCount();xxx++){
if (jtable.getValueAt(xxx,4).equals("1")){
Nilai ="0"+ (String) jtable.getValueAt(xxx,2);
XNilai+=Nilai+",";
} else continue;
System.out.print(XNilai.substring(0,XNilai.lastIndexOf(",")));
jtextfield.setText();
jtextfield.setText(XNilai.substring(0,XNilai.lastIndexOf(",")));
XNilai="";
}
} catch (Exception e){
System.out.print(e);
}
Upvotes: 0
Views: 584
Reputation: 324088
my data i've already wrote is missing
That is what the setText()
method does. It replaces the existing text with the new text.
Instead of using a JTextField
you can try using a JTextArea
, then you can use the following to add text to the end:
textArea.append( "some text" );
If you really want to use a JTextField
then you can use:
Document doc = textField.getDocument();
doc.insertString("some text", doc.getLength(), null);
to append text to the text field.
Upvotes: 5