开发者

MVP, JFrame, JDialog : GUI is freezing

I have main frame (with JFrame field) asi view, then presenter (created in view's constructor) that adds listeners to buttons and stuff. I do that like this:

public static void main(final String[] args) {
        EventQueue.invokeLater(new Runnable() {
            @Override
            publ开发者_如何学编程ic void run() {
                try {
                    MyWindow window = new MyWindow();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

MyWindow invokes in it's constructor only one method - intialize - that only creates GUI fields. Finally (literally last line of it's code) it creates presenter.

Presenter should show new JDialog on certain events in main view. It has one method, that makes my GUI freeze. It looks like this:

protected double[] getParams(final Class<?> indicatorClass) {
        ParametrizableDialog dialog = dialogs.get(indicatorClass); // works well
        List<Double> params = new ArrayList<Double>();
        dialog.setParams(params);
        dialog.setModal(true);
        dialog.setLocationRelativeTo(view.getFrame());
        dialog.setVisible(true);
        System.out.println(params); // it actually works, params are obtained from JDialog as user input
        return Doubles.toArray(params); // guava
    }

ParametrizableDialog is normal JDialog that implements one method interface that sets List<Double> parameters like this:

public class ParametrizableDialog extends JDialog implements Parametrizable {

    protected List<Double> params;

    @Override
    public void setParams(final List<Double> params) {
        this.params = params;
    }

}

Now, does anybody know what mistake did I make and why does my GUI freeze? Thanks!


If a GUI freezes, its generally because your are blocking the EDT. Read the section from the Swing tutorial on Concurrency for more information.

We can't tell what you are doing because your code isn't complete. For example you don't even add any components to the GUI. So who knows what you are doing in the code you left out.

For more help post your SSCCE that demonstrates the problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜