【发布时间】:2013-12-09 20:23:51
【问题描述】:
我有一个应用程序,在进行更改后会出现一个绿色复选标记,表示更改成功。该应用程序有几个可能的更改,我希望能够在 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 行代码的一部分。
-
我的意思是:我什至无法找到它。
-
@MarkoTopolnik 它在最底层
-
如需尽快获得更好的帮助,请发帖SSCCE。
标签: java swing concurrency jbutton event-dispatch-thread