How can Swing dialogs even work?

前端 未结 2 998
Happy的楠姐
Happy的楠姐 2021-02-07 05:29

If you open a dialog in Swing, for example a JFileChooser, it goes somewhat like this pseudocode:

swing event thread {
  create dialog
  add listener to dialog close e         


        
2条回答
  •  礼貌的吻别
    2021-02-07 05:41

    It's the AWT's thread, not Swing's.

    Anyway, AWT runs the dispatch loop within the show. Input events to blocked windows are blocked. Repaint events, events to unblocked windows and general events are dispatched as usual.

    You can see this either by adding the line:

     Thread.dumpStack();
    

    into the even handling for the modal dialog, or more easily from the command line with jstack or use ctrl-\/ctrl-break in the command window of the application.

    The Foxtrot library abuses this to provide a more procedural (as opposed to event-driven) model. It's also used by WebStart/Java PlugIn to provide dialogs for JNLP services and others when called from the application EDT.

提交回复
热议问题