我正在使用 Java Swing 创建一个 JDialog,并且我正在尝试创建一个显示/隐藏详细信息按钮来显示/隐藏此 JDialog 底部的报告。
它对我来说很好,但我想随着时间的推移来做这个,在显示/隐藏报告时添加一个小的动画效果,我使用了 TimerTask 但它只是直接显示报告而没有任何慢动作......这是我当前的代码:
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
);
}
}