Note that there are some explanatory texts on larger screens.

plurals
  1. POjava event queue event dispatch flush/trap events
    primarykey
    data
    text
    <p>I have a design related question that I am trying to find an answer to.</p> <p>Here is the scenario.</p> <p>Suppose that you want to do something expensive (time-consuming) as a result of user input (e.g. loading huge amounts data from some database, reading large files). The strongly recommended way is to do the time-consuming work in a separate thread and never ever block the EDT, or else the GUI will become unresponsive.</p> <p>There are scenarios however when you should not provide inputs to the GUI unless the background task is finished. In my specific case, only after the background work is finished, I can determine which GUI elements should be visible and enabled/disabled. Only those GUI elements which should be visible and enabled should respond to the user inputs otherwise the behavior may be unpredictable in my specific case.</p> <p>This is what I am doing to handle such a scenario.</p> <p>Step 1: Before I am about to start a time-consuming operation.</p> <ol> <li>Change the cursor to a busy cursor.</li> <li>Add mouse listeners to the glasspane of component's top-level frame.</li> <li>Make the glasspane visible so that it can receive mouse events. The glasspane doesn't do anything as a result of mouse inputs.</li> </ol> <p>Step 2: Execute the time-consuming operation in a background thread. The background thread has a finally block that notifies the event thread when the job is finished (completed or aborted due to an error).</p> <p>Step 3:</p> <ol> <li>Switch the mouse cursor back to normal.</li> <li>Remove listeners from the glass pane.</li> <li>Make the glasspane invisible, so that mouse events go to their intended recipients.</li> </ol> <p>Is this the correct approach to handle such situations?</p> <p>What do you guys recommend?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload