SwingWorker does not enter the PropertyChangeListener

0

I created a swingworker to display a JDialog while the code is still waiting for the user to put their finger on the fingerprint reader

Everything worked fine, visible as visible inside the PropertyChangeListener and the digital picking method inside doInBackground.

The problem is that when I put the doInBackuground return a value (which is a string returned by the method of collecting the biometry so I save it in the BD) it does not trigger the STARTED event for the PropertyChangeListener. When you get into it it's already in DONE, so the setdisible (true) of JDialog is not reached.

Here is the code for my SwingWorker:

public class Loader extends SwingWorker<Object, Object> {

    private JDialog dialog;


    public Loader(Frame owner) {
        dialog = new JDialog(owner, "Loading", true);
        dialog.setUndecorated(true);
        JLabel label = new JLabel( new ImageIcon("/opt/workspace/openbravo2/src-beans/com/openbravo/images/fingerinsert.png") );
        dialog.add( label );
        //dialog.add(progressPane);
        dialog.pack();
        dialog.setLocationRelativeTo(owner);
        dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);

        addPropertyChangeListener(new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                if ("state".equals(evt.getPropertyName())) {
                    if (getState() == StateValue.STARTED) {
                        SwingUtilities.invokeLater(new Runnable() {
                            @Override
                            public void run() {
                                if (getState() == StateValue.STARTED) {
                                    dialog.setVisible(true);
                                }
                            }
                        });
                    } 
                } 
            }
        });
    }

    @Override
    protected Object doInBackground() throws Exception {
        return getFingerPrint();
    }

    @Override
    protected void done() {
        dialog.dispose();
    }

}

And here's the call below:

Loader loader = new Loader(null);
loader.execute();

try {
    System.out.println(loader.get());
} catch (InterruptedException | ExecutionException e) {
    e.printStackTrace();
}

So as I said, if I do not put the get () snippet then everything works fine, but with it it does not fire the start event (which I understand is when doBackground starts to run).

Thanks in advance for the help.

    
asked by anonymous 14.01.2016 / 13:36

0 answers