Example usage for javax.swing Timer setCoalesce

List of usage examples for javax.swing Timer setCoalesce

Introduction

In this page you can find the example usage for javax.swing Timer setCoalesce.

Prototype

public void setCoalesce(boolean flag) 

Source Link

Document

Sets whether the Timer coalesces multiple pending ActionEvent firings.

Usage

From source file:Main.java

public static void main(String[] args) {
    JProgressBar pb = new JProgressBar();
    JTextArea ta = new JTextArea(10, 20);

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(new JScrollPane(ta));
    frame.add(pb, BorderLayout.SOUTH);
    frame.pack();/*from w ww . j av a 2  s. com*/
    frame.setVisible(true);

    Timer timer = new Timer(250, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            index++;
            if (index >= 100) {
                ((Timer) (e.getSource())).stop();
            }
            ta.append("Line " + index + "\n");
            pb.setValue(index);
        }
    });
    timer.setRepeats(true);
    timer.setCoalesce(true);
    timer.start();
}

From source file:Main.java

public ClockPane() {
    setLayout(new BorderLayout());
    tickTock();/*from   w w  w .  ja v a  2 s.c  om*/
    add(clock);
    Timer timer = new Timer(500, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            tickTock();
        }
    });
    timer.setRepeats(true);
    timer.setCoalesce(true);
    timer.setInitialDelay(0);
    timer.start();
}

From source file:Main.java

public BlinkPane() {
    label = new JLabel("Hello");
    setLayout(new GridBagLayout());

    add(label);/*from  w w  w.jav  a 2 s.  co m*/
    Timer timer = new Timer(1000, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            on = !on;
            repaint();
        }
    });
    timer.setRepeats(true);
    timer.setCoalesce(true);
    timer.start();
}