Search code examples
javaswingloadingjlabel

Displaying % in a label


So on my project I have an timer with an label which makes it look like it is Loading so i was wondering how would i make it so there is an % in the middle which after 10 seconds goes to 100% so like 1 second is 10% 1.5seconds is 15%

My Timer

    public void actionPerformed(ActionEvent evt) {
        m.setVisible(true);

        Close();
        timer.stop();

    }
}

And the Label Code

Loading = new javax.swing.JLabel();

Loading.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pkgnew/launcher/Images/Loading Program/Loading.gif"))); // NOI18N

getContentPane().add(Loading);
Loading.setBounds(210, 210, 60, 60);

Solution

  • Making progress bars based of a set time is dangerous as a program which runs in 10 seconds on your PC may take 20 on another due to differing hardware, memory e.t.c. What you may want to look into is a JProgressBar to try and track the progress of whatever you are timing.

    Try checking out java2s and Oracle tutorial for a bit more info.