Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #11740

Lightweight postDelayed / removeCallbacks

From Jan Burse <janburse@fastmail.fm>
Newsgroups comp.lang.java.programmer
Subject Lightweight postDelayed / removeCallbacks
Date 2012-02-04 20:44 +0100
Organization albasani.net
Message-ID <jgk1q9$9o1$1@news.albasani.net> (permalink)

Show all headers | View raw


Dear All,

Just fidling around with a Android / Swing port.
Just wonder whether somebody has worked on an
untility to provide the following under Swing
which is inspired by the Android View(*):

    postDelayed(Runnable r, int d):
         Posts an event on the EDT, which will
         invoked r after a delay of d millisecond.

    removeCallbacks(Runnable r):
         Immediately remove all events from the
         EDT that would invoke r.

One could use javax.swing.Timer for the first
method. Something along:

     public void postDelayed(final Runnable r, int d) {
         final Timer t=new Timer(d,new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                r.run();
             }
         });
         t.setRepeats(false);
         t.start();
     }

But then for the second method one would need to
track the created timers, so as to be able to
selectively stop them.

Anybody already implemented a corresponding utility
in the spirit of SwingUtil.invokeLater/invokeAndWait?
Would be glad to receive hint so as not to reinvent
the wheel.

Bye

(*)
http://developer.android.com/reference/android/view/View.html

Back to comp.lang.java.programmer | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Lightweight postDelayed / removeCallbacks Jan Burse <janburse@fastmail.fm> - 2012-02-04 20:44 +0100
  Re: Lightweight postDelayed / removeCallbacks Steven Simpson <ss@domain.invalid> - 2012-02-05 22:00 +0000
    Re: Lightweight postDelayed / removeCallbacks Jan Burse <janburse@fastmail.fm> - 2012-02-06 01:15 +0100
      Re: Lightweight postDelayed / removeCallbacks Jan Burse <janburse@fastmail.fm> - 2012-02-06 01:35 +0100

csiph-web