Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] Display.asyncExec premepts pending events


In readAndDispatch(), it seems like SWT prioritizes pending OS events above Runnables that were posted asynchronously (based on the fact that this method calls runDeferredEvents(), and then runAsyncMessages()). The problem for me is that runAsyncMessages() in Display does not behave like I expect.  At the time when runAsyncMessages() is called, I would expect it to run *only* the messages that are currently on the queue at that time.  But, if one of those Runnables re-posts itself to the async queue, runAsyncMessages() never returns.  This is the problem I am having.

It seems like readAndDispatch() might also work if it never dispatched more than a single message, therefore runAsyncMessages() would only run the first item in the queue.

Here is the AWT version of what I am trying to do.  (BTW, it works, meaning UI events are prioritized)

public static void main(String[] args) {
        Frame frame = new Frame();
        Panel contents = new Panel();

        final JPanel panel = new JPanel();
        panel.setPreferredSize(new Dimension(30,30));
        frame.add(contents);
        frame.setSize(300,300);

        contents.add(new Button("foo"));
        contents.add(new Button("foo"));
        contents.add(panel);

        SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                        if (panel.getBackground() == Color.gray)
                                panel.setBackground(Color.darkGray);
                        else
                                panel.setBackground(Color.gray);
                        panel.repaint();
                        SwingUtilities.invokeLater(this);
                }
        });
        frame.addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                        System.exit(0);
                }
        });
        frame.show();
}

Back to the top