Search code examples
javaeclipsejbutton

java: remove(component); does not remove button instantly


so I'm using this to remove the button from the JPanel. However, the button is not removed instantly, but disappears only after I minimize the window. Any suggestions?

   jBOption2.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){

                    jPanel.remove(jButton2);

Solution

  • Correct me if I'm wrong, but I think it should work the same way as mentioned in this post: https://stackoverflow.com/questions/11438512/...

    jPanel.remove(jButton2);
    jPanel.revalidate();
    jPanel.repaint();
    

    I hope it fits your question ;)