我有一个应用程序,在更改后会出现一个绿色复选标记,表示更改成功。该应用程序有几个可能的变化,我希望能够让复选标记在2.5秒后消失。我已经尝试了几件事情,如:使项目消失
panel.add(checkMark);
checkMark.setVisible(true);
panel.remove(checkMark);
checkMark.setVisible(false);
似乎没有任何工作。我添加了一个timer
电话,然后是checkMark.setVisible(false)
,没有任何东西似乎有帮助。
有人请指出我做错了什么吗?以下是我的代码:
//Create Change Role Button
final JButton changeRoleBtn = new JButton("Change Role");
changeRoleBtn.setBounds(50, 500, 150, 30);
changeRoleBtn.setToolTipText("Changes the role of the User");
changeRoleBtn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
//Create Success Image
final ImageIcon i1 = new ImageIcon("/Users/vhaislsalisc/Documents/workspace/Role_Switcher/greenCheck.png");
final JLabel checkMark = new JLabel(i1);
checkMark.isOptimizedDrawingEnabled();
i1.paintIcon(changeRoleBtn, getGraphics(), 400,25);
checkMark.setVisible(true);
try
{
timer = new Timer(2000, new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
checkMark.setVisible(false);
timer.stop();
}
});
timer.start();
}
catch(Exception e5)
{
e5.printStackTrace();
timer.stop();
}
}
});
这是关于计时器的一点。其他代码是相关的,因为它包括我对图形的声明以及它如何被调用和使用。
try
{
timer = new Timer(2000, new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
checkMark.setVisible(false);
timer.stop();
}
});
timer.start();
}
catch(Exception e5)
{
e5.printStackTrace();
timer.stop();
}
请问您的200多行JDBC代码与这个问题有什么关系?另一方面,你甚至没有用'Timer'来显示你的尝试,这是唯一重要的事情。 –
计时器的尝试是200行代码的一部分。 – DarthOpto
我的观点正是:我甚至无法找到它。 –