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 6376567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:45:44+00:00 2026-05-25T01:45:44+00:00

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { int count = jSlider1.getValue(); int delay = jSlider2.getValue(); int

  • 0
   private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
  int count = jSlider1.getValue(); 
  int delay = jSlider2.getValue();
    int valueOfSlider = jSlider2.getValue();
     int valueOfSlider2 = jSlider1.getValue();

while (count > 0) 
{ 
    count--;
    String count2 = ""+count; 
  jLabel3.setText(count2);
try {Thread.sleep(delay); }
catch (InterruptedException ie) { }

 }

It will eventually show the final number on the jLabel but it does not incrementally update the number. any help

  • 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-05-25T01:45:45+00:00Added an answer on May 25, 2026 at 1:45 am

    Swing is single-threaded. Therefore, long-running tasks should never take place in the EDT. This includes sleeping. Instead, use a javax.swing.Timer. This will delay in a background thread, and then post an action to be executed in the EDT.

    See also:

    • How to Use Swing Timers

    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.Font;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.SwingUtilities;
    import javax.swing.Timer;
    
    public final class JLabelUpdateDemo {
    
        public static void main(String[] args){
            SwingUtilities.invokeLater(new Runnable(){
                @Override
                public void run() {
                    createAndShowGUI();             
                }
            });
        }
    
        private static void createAndShowGUI(){
            final JFrame frame = new JFrame("Update JLabel Demo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().setLayout(new FlowLayout());
            frame.getContentPane().add(JTimerLabel.getInstance());
            frame.setSize(new Dimension(275, 75)); // used for demonstration purposes
            //frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
    
            Timer t = new Timer(1000, new ActionListener(){
                @Override
                public void actionPerformed(ActionEvent e) {
                    int val = Integer.valueOf(JTimerLabel.getInstance().getText());
                    JTimerLabel.getInstance().setText(String.valueOf(++val));
                }
            });
            t.start();
        }
    
        private static final class JTimerLabel extends JLabel{
            private static JTimerLabel INSTANCE;
    
            private JTimerLabel(){
                super(String.valueOf(0));
                setFont(new Font("Courier New", Font.BOLD,  18));
            }
    
            public static final JTimerLabel getInstance(){
                if(INSTANCE == null){
                    INSTANCE = new JTimerLabel();
                }
    
                return INSTANCE;
            }
        }
    }
    

    This SSCCE imitates a counter that will count up from 0 every second (i.e. update the JLabel instance) until the application is terminated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This jSlider code causes the application to hang. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { //
I write action performed code like outside of main private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
private void save(Rectangle src, Rectangle dest, string fName, int width, int height, Bitmap file)
private void dateTimePicker1_ValueChanged(object sender, Series myseries, int multiplier, EventArgs e) { if (datelimitsset ==
private void btnMiles_Click(object sender, EventArgs e) { try { int milesless200 = int.Parse(txtMiles.Text); int
private void DoSomeWork() { ManualResetEvent[] waitEvents = new ManualResetEvent[rowCount]; int i = 0; foreach
BHere's the code: c# private void button1_Click(object sender, EventArgs e) { int a =
private void BindFields() { DataTable table = Globals.ConvertDataReaderToDataTable(DataProvider.GetFields()); _fieldCount = table.Rows.Count; dataGrid.DataSource = table;
private void button1_Click(object sender, EventArgs e) { int[] ml = new int[10] ( 1,
private void activateRecords(long[] stuff) { ... api.activateRecords(Arrays.asList(specIdsToActivate)); } Shouldn't this call to Arrays.asList return

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.