Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9167359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:22:17+00:00 2026-06-17T15:22:17+00:00

I want to show how merge sort perform visually using JFrame . What I

  • 0

I want to show how merge sort perform visually using JFrame. What I want to do is to make visible subsequent JLabel with some time delay. I tried many way but all of them appears at same moment with no intermediate delay.

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
       // jLabel1.setVisible(false);
        jLabel2.setVisible(false);
        jLabel3.setVisible(false);
        jLabel4.setVisible(false);
        jLabel5.setVisible(false);
        jLabel6.setVisible(false);
        jLabel7.setVisible(false);
        final Timer t=new Timer((4000), null);
         final int delay=2000;
        final ActionListener taskPerformer = new ActionListener() {
      public void actionPerformed(ActionEvent evt) {

          jLabel1.setVisible(true);
          t.getDelay();

          jLabel2.setVisible(true);
          t.setDelay(3000);

          jLabel3.setVisible(true);
          t.setDelay(2000);

          jLabel4.setVisible(true);
          t.setDelay(2000);

          jLabel5.setVisible(true);
          t.setDelay(2000);

          jLabel6.setVisible(true);
          t.setDelay(2000);
                }
  };

  new Timer(delay, taskPerformer).start();

But when I click button all the lables appear at same momenet though I have kept delay.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:22:18+00:00Added an answer on June 17, 2026 at 3:22 pm

    There are a number of reasons why this won’t work. Firstly, javax.swing.Timer doesn’t work this way. It waits in the background until the given delay has past and then calls the registered ActionListeners actionPerformed method.

    Secondly, if it did work this way, it would block the Event Dispatching Thread, preventing it from processing repaint requests.

    I think you will find How to use Swing Timers of use.

    public class BlinkOut {
    
        public static void main(String[] args) {
            new BlinkOut();
        }
    
        public BlinkOut() {
            EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    try {
                        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                    }
    
                    JFrame frame = new JFrame("Test");
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.setLayout(new BorderLayout());
                    frame.add(new TestPane());
                    frame.pack();
                    frame.setLocationRelativeTo(null);
                    frame.setVisible(true);
                }
    
            });
        }
    
        public class TestPane extends JPanel {
    
            private JLabel[] labels;
            private int[] delays;
            private Timer timer;
            private int index;
    
            public TestPane() {
                setLayout(new GridLayout(0, 1));
                labels = new JLabel[7];
                for (int index = 0; index < 7; index++) {
                    labels[index] = new JLabel("Label " + (index + 1));
                    add(labels[index]);
                }
                delays = new int[] {2000, 3000, 2000, 2000, 2000, 2000, 2000};
                JButton hide = new JButton("Hide");
                add(hide);
                hide.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        System.out.println("Click");
                        index = 0;
                        labels[index].setVisible(false);
                        timer.setDelay(delays[index]);
                        timer.start();
                    }
                });
                timer = new Timer(delays[0], new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        System.out.println("Tick");
                        timer.stop();
                        index++;
                        if (index < 7) {
                            labels[index].setVisible(false);
                            timer.setDelay(delays[index]);
                            timer.start();
                        }
                    }
                });
                timer.setRepeats(false);
                timer.setCoalesce(true);
            }
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Drupal 7 and Views module in my site. And want show number
I want to show array objects at the same time in different 10 labels.
I want to show a border type look for an element but without using
I want to show a welcome screen as well as some basic tutorials of
I want to show the content of a nested table using a cursor. I've
I want to merge two rows and add a column to show the count
I want show an information page after success db opartions. And after the info
I want show annotation view (above one of my pin) after load map. For
hii I want show a pop up Dialog box when i click on to
I want to show my groupview with 2 lines to down direction, but only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.