java - How to update JTextfield after click SAVE button -
i have main frame : jframe>contentframe>scrollpane>bigpanel>panel_1t
private jpanel contentpane; private jpanel bigpanel; private jpanel panel_1t;
in panel_1t, have put food button actionlistener:
jbutton button_19 = new jbutton("food"); button_19.addactionlistener(new actionlistener() { public void actionperformed(actionevent ae) { newfoodui nf = new newfoodui();//open other class nf.setvisible(true); nf.setdefaultcloseoperation(windowconstants.dispose_on_close); } }); panel_1t.setlayout(new gridlayout(0, 2, 0, 0)); panel_1t.add(button_19);
when user click food button, new jframe in newfoodui
class shown.: jframe>contentpane>panel>tabbedpane>panel_3>panel_5
in panel_5, put jtextfield:
public static jtextfield textfield_3; textfield_3 = new jtextfield(); panel_5.add(textfield_3, "9, 4, fill, default"); textfield_3.setcolumns(10);
user write text textfield_3
. user click save button in panel_3, perform this:
jbutton button_4 = new jbutton("save"); button_4.addactionlistener(new actionlistener() { public void actionperformed(actionevent e) { setcontentpane(contentpane); panel_3.revalidate(); panel_3.repaint(); panel_3.updateui(); panel_5.revalidate(); panel_5.repaint(); panel_5.updateui(); contentpane.revalidate(); contentpane.repaint(); joptionpane.showmessagedialog(null, "saved !"); } }); button_4.setbounds(873, 396, 75, 33); contentpane.add(button_4); }
the result is, when click save button , close frame in newfoodui, reopen click food button check whether text wrote has been saved or not. not saving text wrote.
you have save value textfeld textfield_3.gettext()
, set value manually textfeld when showing textfield_3.settext(value)
. have keep value in project or store persistent somewhere.
Comments
Post a Comment