Possible Duplicate:
Pretty alternative to JProgressBar?
I have a process which takes several seconds to load, and I want to create an animation in Java Swing until it finishes loading.
I'd like to avoid using a typical ProgressBar and use a nice modern infinite progress like this one
I'm aware of similar questions but this is strictly Java Swing related. Is there any library or example for this?
It's easy to make a simple CSS loading animation. Let's walk through how to make the following loading spinner. First, add a div in HTML and define it with the classname "loader." Next, use the CSS class selector .loader to customize your CSS loading animation. You can define mutliple properties, as shown in the rule set below.
And fortunately, the designer of this animation realizes this psychological fact of users and especially add quickly rotating color bars and rapidly changing numbers to tell users that this web/app is processing their problems in the background quickly. This Loading animation is really a nice shot to offer users a much more pleasant experience.
The simplest method is creating a loading gif. Gif is an image format used for simple animations. it’s fairly popular and easy to use. CSS loader is another popular choice among developers.
There are many different tools that can build loading animations. However, one of the most practical ones is CSS. Let's explore why in the section below. To be clear, you could use another coding language like JavaScript (JS) or a simple animated GIF for your loader.
Just use a ImageIcon
for this task, it automatically animates gifs. The code below produced this screenshot (the ajax-loader.gif
was downloaded from http://www.ajaxload.info/):
public static void main(String[] args) throws Exception {
JFrame frame = new JFrame("Test");
ImageIcon loading = new ImageIcon("ajax-loader.gif");
frame.add(new JLabel("loading... ", loading, JLabel.CENTER));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 300);
frame.setVisible(true);
}
I'd recommend using the glasspane for this type of activity. The steps involved are:
JComponent
with BorderLayout
. Add a JLabel
to the CENTER
which includes the animated .gif icon of your choice.paint(Graphics)
method to make your GUI appear greyed out (or whited out). To achieve this you need to draw a filled rectangle the size of the component, filling the rectangle with a semi-transparent Color.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With