J'utilise Java Swing pour créer un JDialog, et j'essaie de créer un bouton Afficher/Masquer les détails pour afficher/masquer un rapport au bas de ce JDialog.Comment créer un bouton Afficher/Masquer les détails?
Cela fonctionne bien pour moi, mais je veux le faire avec le temps, pour ajouter un petit effet d'animation tout en montrant/masquant le rapport, j'ai utilisé TimerTask mais il montre juste le rapport directement sans ralentir ... Voici mon code actuel:
private void showHideDetailsButtonActionPerformed() {
final MyDialog myDialog = this;
int fullHeight = this.getHeight();
int smallHeight = this.getHeight()/2 - 4;
this.setSize(this.getWidth(), smallHeight); // By default hide the report.
if(this.getHeight() == smallHeight) { // Show details.
new Timer().schedule(
new java.util.TimerTask() {
@Override
public void run() {
while(myDialog.getHeight() < fullHeight) {
myDialog.setSize(myDialog.getWidth(), myDialog.getHeight() + 1);
System.out.println(myDialog.getHeight());
}
}
},
800
);
}
}
Parfait ... javax.swing.Timer est si simple et fait le travail. – Brad