title: Disabling remaining Buttons, On Click of one button
body: <p>I have a small problem while disabling/enabling buttons in Swing Application.
  It's a very basic problem, but  I'm  new to this concept.</p>
  
  <p>I have a requirement like, having 2 buttons to perform 2 individual operations.</p>
  
  <ol>
  <li>While Running initially B1 &amp; B2 Should be Visible/Enabled.</li>
  <li>If B1 Clicked, then B2 should be disabled/Invisible. After B1 work Completed, then Both B1 &amp; B2 Should be Visible/Enabled.</li>
  <li>If B2 Clicked, then B1 should be disabled/Invisible.
  After B2 work Completed, then Both B1 &amp; B2 Should be Visible/Enabled.</li>
  </ol>
  
  <p>But, my problem, is, after processing B1/B2 SetEnable/SetVisible is working. It should be disabled before start and enabled after completing task</p>
  
  <p>Can anyone help in this case?</p>
  
  <p>Below is my Code</p>
  
  <pre><code>import java.awt.Font;
  import java.awt.GridLayout;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  import javax.swing.WindowConstants;
  
  public class FinCSV implements ActionListener {
  
    JFrame frame = new JFrame("ICON");
    JPanel panel = new JPanel(new GridLayout(2, 1, 4, 4));
    JButton primaryButton = new JButton(" Primary Process");
    JButton secondaryButton = new JButton(" Secondary Process");
  
    public static void main(String[] args)
          throws Exception {
      FinCSV msql = new FinCSV();
      msql.initGUI();
    }
  
    public void initGUI() {
      this.primaryButton.setActionCommand("Primary");
      this.secondaryButton.setActionCommand("Secondary");
      this.primaryButton.addActionListener(this);
      this.secondaryButton.addActionListener(this);
  
      this.primaryButton.setFont(new Font("Serif", Font.BOLD, 22));
      this.secondaryButton.setFont(new Font("Serif", Font.BOLD, 22));
  
      panel.add(this.primaryButton);
      panel.add(this.secondaryButton);
      frame.setContentPane(panel);
      frame.setSize(650, 300);
      frame.setVisible(true);
      frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }
  
    public void actionPerformed(ActionEvent e) {
  
      if (e.getActionCommand().equals("Primary")) {
           secondaryButton.setVisible(false);
          // secondaryButton.setEnabled(false);
          for (int i = 0; i &lt; 10000; i++) {
              System.out.println("[ " + (i + 1) + " ] Inside Primary Process");
          }
            secondaryButton.setVisible(true);
           // secondaryButton.setEnabled(true);
      } else if (e.getActionCommand().equals("Secondary")) {
          primaryButton.setVisible(false);
           // primaryButton.setEnabled(false);
          for (int i = 0; i &lt; 10000; i++) {
              System.out.println("[ " + (i + 1) + " ] Inside Secondary Process");
          }
          primaryButton.setVisible(true);
        // primaryButton.setEnabled(true);
      }
    }
  }
  </code></pre>