I want to make a circle progress like this:
In Java, I could only find something about JProgressBar
.
There is class AnimatedIcon
- non-default on the Java platform - which apparently suits what you're wanting to do, I do not know if visually it will look the way you expect but the idea of displaying a circle to tell you that something is being loaded is the same.
The simplest (and also the one I use) for this kind of situation is to simply insert an animated image with .gif extension into a JLabel
. Using the setIcon()
you can do this.
There are several sites that provide these loading circles on the internet, so Google can help you find one that fits your needs. Preloaders and SpiffyGif are good and allow you to customize some options existing, I ended up doing a very quick example on the first site to test:
Havingthisimage,justputitasaresourceinyourproject.ThenyoucancreateamethodtoreturnaJPanel
/JLabel
containingthisimageasanicon,whichdefinesyou.Asnothingwasspecifiedinthequestion,IcreatedanexamplewiththeaboveimagebeinginserteddirectlyintoJFrame
,theresultisthis:
Andfollowthecode:
importjava.awt.*;importjavax.swing.*;importjava.net.URL;publicclassLoadingTestextendsJFrame{publicLoadingTest(Stringtitle){super(title);//PropriedadesdoJFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);setLayout(newFlowLayout());setSize(150,150);//Obtendoorecurso(nocaso,aimagemde'loading').ImageIconloadingImage=newImageIcon(getClass().getResource("loading.GIF"));
// Instanciando um novo JLabel e definindo a imagem encontrada como ícone.
JLabel loadingLabel = new JLabel();
loadingLabel.setIcon(loadingImage);
// Inserindo o JLabel no Frame.
getContentPane().add(loadingLabel);
}
public static void main(String... args) {
SwingUtilities.invokeLater(() -> {
new LoadingTest("Testando Loading").setVisible(true);
});
}
}