Hi, I'm writing an application that do some task and inform user upon successful completion of the task. To inform user I am using a jlabel. I want this jlabel to display the message and fadeaway after a while. I am using netbeans as my IDE.
Here is the architecture of my classes.
Abstract, GUI code
abstract class Admin extends JFrame{
protected static jlabel lbl_message= new jlabel("some text");
// other functions and variables
abstarct protected void performButtonClickAction();
}
Class for implementing abstract functions and providing other functionalities.
final class AdminActionPerformer extends Admin{
final public void performButtonClickAction(){
// code for doin the task
if(task is successful){
new Thread(new Fader(Admin.lbl_message)).start();
}
}
public static void main(String[] args) {
new AdminActionPerformer().setVisible(true);
}
}
Thread for making the Jlabel fadeaway
class Fader implements Runnable{
javax.swing.JLabel label;
Color c;
Fader(javax.swing.JLabel label){
this.label=label;
c=label.getBackground();
}
public void run() {
int alpha=label.getGraphics().getColor().getAlpha()-5;
while(alpha>0){
System.out.println(alpha);
alpha-=25;
label.getGraphics().setColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), alpha));
label.repaint();
try {
Thread.sleep(50);
} catch (InterruptedException ex) {
Logger.getLogger(Fader.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
But the label does not fadeaway. What am I doing wrong here? Thank you :)
P.S. I have set JLabel opaque true. Is that a problem? I want to display the label with its background colour initially and then make it fade away.