Java Swing JTextField.getText is not returning anything -
for reason gettext not working text field.
perhaps doing wrong this.
private jtextfield txttemp; txttemp = new jtextfield(); txttemp.setbounds(350, 57, 86, 20); mainpanel.add(txttemp); txttemp.setcolumns(10); string filepath = txttemp.gettext(); system.out.println("file path is" +filepath);
nothing beingness printed when typed in text box.
i did using action listener. load program, , have user add together text.
btntest = new jbutton("test"); btntest.addactionlistener(new actionlistener() { public void actionperformed(actionevent arg0) { string filepath = txttemp.gettext(); system.out.println("file path is" +filepath); } });
still returns blank.
any ideas?
"nothing beingness printed when typed in text box."... "still returns blank."
sounds want happen whenever text field beingness type into. utilize documentlistener
, listener changes in underlying document
of text field.
final jtextfield field = new jtextfield(20); field.getdocument().adddocumentlistener(new documentlistener(){ @override public void insertupdate(documentevent e) { printtext(); } @override public void removeupdate(documentevent e) { printtext(); } @override public void changedupdate(documentevent e) { printtext(); } private void printtext() { system.out.println(field.gettext()); } });
see more explanation @ how write document listener aside, if want happen when utilize type enter, add together actionlistener
text field.
java swing
No comments:
Post a Comment