title: How to Prevent Redirection to the selected Tab in JTabbedPane?
body: <p>i've created an application in java swing.<br>
  The application is a <code>JFrame</code> with a <code>JTabbedPane</code> with 3 tabbedpanes.  </p>
  
  <p>In the first pane there is a progress checkbox, if the checkbox is select then on clicking on to another panes i'e 2nd or 3rd pane will get a <code>ERROR</code> message showing "Tabbed 1 in progress".  </p>
  
  <p>The problem is that when i click on to other panes when the progress checkbox is selected, It will first goes to the pane which i selected then only the redirection works and also the Error message is executed twice.</p>
  
  <p>i've prevented Twice execution of Error message somehow , but can't prevent going to clicked pane when the progress checkbox is clicked.  </p>
  
  <p>Can anyone please tell me some solution for this problem.</p>
  
  <p>my complete code is given below.</p>
  
  <pre><code>import javax.swing.JOptionPane;
  
  public class sample extends javax.swing.JFrame {
  public static int status=0;
      public sample() {
          initComponents();
      }
  
      @SuppressWarnings("unchecked")
      // &lt;editor-fold defaultstate="collapsed" desc="Generated Code"&gt;
      private void initComponents() {
  
          tab = new javax.swing.JTabbedPane();
          jDesktopPane2 = new javax.swing.JDesktopPane();
          jLabel1 = new javax.swing.JLabel();
          progress = new javax.swing.JCheckBox();
          jDesktopPane4 = new javax.swing.JDesktopPane();
          jLabel2 = new javax.swing.JLabel();
          jDesktopPane5 = new javax.swing.JDesktopPane();
          jLabel3 = new javax.swing.JLabel();
  
          setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  
          tab.setTabLayoutPolicy(javax.swing.JTabbedPane.SCROLL_TAB_LAYOUT);
          tab.setTabPlacement(javax.swing.JTabbedPane.LEFT);
          tab.addChangeListener(new javax.swing.event.ChangeListener() {
              public void stateChanged(javax.swing.event.ChangeEvent evt) {
                  tabStateChanged(evt);
              }
          });
  
          jDesktopPane2.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.background"));
  
          jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
          jLabel1.setText("TABBED PANE 1  BODY ");
          jLabel1.setBounds(50, 60, 230, 40);
          jDesktopPane2.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);
  
          progress.setText("Progress");
          progress.addItemListener(new java.awt.event.ItemListener() {
              public void itemStateChanged(java.awt.event.ItemEvent evt) {
                  progressItemStateChanged(evt);
              }
          });
          progress.setBounds(50, 40, 90, 23);
          jDesktopPane2.add(progress, javax.swing.JLayeredPane.DEFAULT_LAYER);
  
          tab.addTab("Tabbed Pane 1", jDesktopPane2);
  
          jDesktopPane4.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.background"));
  
          jLabel2.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
          jLabel2.setText("TABBED PANE 2  BODY ");
          jLabel2.setBounds(30, 90, 230, 40);
          jDesktopPane4.add(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);
  
          tab.addTab("Tabbed Pane 2", jDesktopPane4);
  
          jDesktopPane5.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.background"));
  
          jLabel3.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
          jLabel3.setText("TABBED PANE 3  BODY ");
          jLabel3.setBounds(60, 160, 230, 40);
          jDesktopPane5.add(jLabel3, javax.swing.JLayeredPane.DEFAULT_LAYER);
  
          tab.addTab("Tabbed Pane 3", jDesktopPane5);
  
          javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
          getContentPane().setLayout(layout);
          layout.setHorizontalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(tab, javax.swing.GroupLayout.PREFERRED_SIZE, 402, javax.swing.GroupLayout.PREFERRED_SIZE)
          );
          layout.setVerticalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(tab, javax.swing.GroupLayout.DEFAULT_SIZE, 315, Short.MAX_VALUE)
          );
  
          pack();
      }// &lt;/editor-fold&gt;
  
      private void progressItemStateChanged(java.awt.event.ItemEvent evt) {
        if(progress.isSelected())
            setStatus(1);
        else
            setStatus(0); 
      }
  
      private void tabStateChanged(javax.swing.event.ChangeEvent evt) {
         int o=getStatus();
         if(o==1)
         {
          JOptionPane.showMessageDialog(null, "Tabbed 1 Progress!!!", "Confirmation!!!",JOptionPane.ERROR_MESSAGE);
          setStatus(0);
          tab.setSelectedIndex(0);
          setStatus(1);
         }
      }
  
      public static void main(String args[]) {
          java.awt.EventQueue.invokeLater(new Runnable() {
  
              public void run() {
                 sample s= new sample();
                 s.setLocationRelativeTo(null);
                 s.setVisible(true);
              }
          });
      }
      // Variables declaration - do not modify
      private javax.swing.JDesktopPane jDesktopPane2;
      private javax.swing.JDesktopPane jDesktopPane4;
      private javax.swing.JDesktopPane jDesktopPane5;
      private javax.swing.JLabel jLabel1;
      private javax.swing.JLabel jLabel2;
      private javax.swing.JLabel jLabel3;
      private javax.swing.JCheckBox progress;
      private javax.swing.JTabbedPane tab;
      // End of variables declaration
  
      public static void setStatus(int i) {
         status=i;
      }
      public static int getStatus()
      {
          return status;
      }
  }
  </code></pre>