swing - Creating GUI components dynamically in java -


so, can create example button dynamically:

panel.add(new jbutton("button")); validate(); 

but question is, how make calls elements later? example, how add event listener button created above, like, 100 lines of code later?

create variable jbutton:

jbutton jbutton = new jbutton("button"); panel.add(jbutton); validate(); /*  *  * 100 lines of code   *  */  // add event listener jbutton.addactionlistener((actionevent) -> {             //         }); 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -