Note that there are some explanatory texts on larger screens.

plurals
  1. POMake an item disappear
    text
    copied!<p>I have an application which after a change is made a green check mark appears indicating success of the change. The application has several possible changes which could be made and I would like to be able to have the check mark disappear after 2.5 seconds. I have tried several things like:</p> <pre><code>panel.add(checkMark); checkMark.setVisible(true); panel.remove(checkMark); checkMark.setVisible(false); </code></pre> <p>Nothing seems to be working. I added a <code>timer</code> call followed by a <code>checkMark.setVisible(false)</code> and nothing seems to be helping. </p> <p>Could someone please point out what I am doing incorrectly? Below is my code:</p> <pre><code>//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(); } } }); </code></pre> <p>Here is the bit about the timer. The other code is relevant, as it includes my declaration for the graphic and how it is being called and used. </p> <pre><code>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(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload