java - Default Button after dispose and setVisible -


given following code:

public class dialogtest implements actionlistener {   public static void main(string[] args) {dialogtest g = new dialogtest();}    public dialogtest() {     jbutton b1 = new jbutton("button a");     b1.addactionlistener(this);     jdialog d = new jdialog();     d.setdefaultcloseoperation(jdialog.dispose_on_close);     jpanel p = new jpanel();     p.add(b1);     d.add(p);     d.getrootpane().setdefaultbutton(b1);     d.pack();     d.setvisible(true);     d.dispose();     d.pack();     d.setvisible(true);   }    public void actionperformed(actionevent e) {system.out.println("hello");} } 

shouldn't pressing enter key write console? according docs (http://java.sun.com/javase/7/docs/api/java/awt/window.html#dispose()):

the window , subcomponents can made displayable again rebuilding native resources subsequent call pack or show. the states of recreated window , subcomponents identical states of these objects @ point window disposed

is intended behaviour?

the reason in jbutton.removenotify (which seems called @ dispose) defaultbutton reset:

overrides jcomponent.removenotify check if button set default button on rootpane, , if so, sets rootpane's default button null ensure rootpane doesn't hold onto invalid button reference.


public void removenotify() {     jrootpane root = swingutilities.getrootpane(this);     if (root != null && root.getdefaultbutton() == this) {         root.setdefaultbutton(null);     }     super.removenotify(); } 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -