Can any one tell me how a JButton appears[Fade in], after a short delay.I am working with Netbeans - drag and drop concept for all components.
Asked
Active
Viewed 1,012 times
2 Answers
0
Personally I would look at making a class that extends your JButton and overriding the paint method. Use both the JTimer to change the values of "setComposite()" (found in the graphics2D class) method over time.
Example of changing the composite in java:
AlphaComposite newComposite =
AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f)
g2d.setComposite(newComposite);

cworner1
- 461
- 4
- 13
-
1You could also check out [this](http://stackoverflow.com/questions/13203415/how-to-add-fade-fade-out-effects-to-a-jlabel/13203744#13203744) example – MadProgrammer Nov 27 '12 at 09:08
0
Here is the code that i found on which the above problem working.
import java.awt.Color;
import java.util.Timer;
import java.util.TimerTask;
public class delay extends javax.swing.JFrame {
Timer timer;
public delay(int seconds) {
initComponents();
jButton1.setVisible(false);
getContentPane().setBackground(Color.red);
timer = new Timer();
timer.schedule(new RemindTask(), seconds*1000);
}
class RemindTask extends TimerTask{
public void run() {
jButton1.setVisible(true);
timer.cancel();
}
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new delay(5).setVisible(true);
}
});
}
}

Sam
- 364
- 2
- 6
- 17