java - get values of Jtextfields when click OK in Dialog -


my need display tab in jdialog (confirmdialog or inputdialog). tab contains 2 jtextfield per row. display works fine :

enter image description here

but don't know how values of jtextfields.

here display code :

int size = model.getcheckedapplications().size(); // une ligne par application sélectionnée layout = new gridlayout(size + 1, 3, 5, 5); mypanel = new jpanel(layout); mypanel.add(new jlabel("application")); mypanel.add(new jlabel("version cadre")); mypanel.add(new jlabel("nouvelles natures")); (application app : model.getcheckedapplications()) {     mypanel.add(new jlabel(app.getcode88()));     jtextfield versionactuellefield = new jtextfield(30);     versionactuellefield.setname("versionactuelle"             + app.getcode88());     versionactuellefield.settext(app             .getversioncadreactuelle());      jtextfield nouvellesnaturesfield = new jtextfield(             30);     nouvellesnaturesfield.setname("nouvellesnatures"             + app.getcode88());      mypanel.add(versionactuellefield);     mypanel.add(nouvellesnaturesfield); } result = joptionpane.showconfirmdialog(null, mypanel,         "valeurs de cette version",         joptionpane.ok_cancel_option); 

then don't know how values when user clicks on ok button :

if (result == 0) { // user clicks on ok button 

you need add them list store, can @ them again. since adding them in reference application, suggest map

private map<application, jtextfield> nouvellesnaturesfields = new arraylistmultimap<application, jtextfield>(); //or hashmap, if key unique private map<application, jtextfield> versionactuellefields = new arraylistmultimap<application, jtextfield>();  public list<jtextfield> getnouvellesnaturesfields() {     return nouvellesnaturesfields ; }  public list<jtextfield> getversionactuellefields () {     return versionactuellefields ; }     //class code  (application app : model.getcheckedapplications()) {     //other code     jtextfield nouvellesnaturesfield = new jtextfield(             30);     nouvellesnaturesfield.setname("nouvellesnatures"             + app.getcode88());     nouvellesnaturesfields.put(app, nouvellesnaturesfield);      //other code , same new nature fields } result = joptionpane.showconfirmdialog(null, mypanel,         "valeurs de cette version",         joptionpane.ok_cancel_option); 

then when user clicks confirm button, using property accessor getnouvellesnaturesfields()or getversionactuellefields() can iterate fields created, so:

for (map.entry<application, jtextfield> entry: mymap.entries()) {     //do here } 

or them via:

for (application app : model.getcheckedapplications()) {     list<jtextfield> data = mymap.get(app);     for(jtextfield field : data) {         field.gettext();     } } 

since key value won't unique, used arraylistmultimap, if unique, hashmap should suffice


Comments

Popular posts from this blog

php - isset function not working properly -

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -