Swing button not being added -


i newbie swing. have written code frame having button when clicked new frame opens. don't know whats wrong code new frame/window not containing button have added in code.

settitle("frame1");     setsize(250, 250);     setdefaultcloseoperation(1);     setvisible(true);      jpanel panel1= new jpanel();     getcontentpane().add(panel1);     jbutton button1= new jbutton();     button1.settext("click open new window");     button1.setbounds(20, 15, 14, 18);     button1.addactionlistener(new actionlistener() {          @override         public void actionperformed(actionevent arg0) {             jframe newframe= new jframe();             newframe.setbounds(150, 150, 150, 150);             newframe.setdefaultcloseoperation(1);             newframe.settitle("new frame");             newframe.setvisible(true);             jpanel panel2= new jpanel();             getcontentpane().add(panel2);             jbutton button2= new jbutton();             button2.settext("quit");             button2.setbounds(10, 5, 4, 8);             panel2.add(button2);             button2.addactionlistener(new actionlistener() {                  @override                 public void actionperformed(actionevent arg0) {                     system.exit(0);                  }             });          }     });          panel1.add(button1);} 

please help!

you add jbutton button1 jpanel panel1 don't add jpanel pane1 jframe itself.

you need add jpanel panel1 jframe

add(panel1); 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -