Example : How to Clean/Clear/Refresh/Cancel/Reset the java controls.

public void clear()
    {
        jTxtRegName.setText("");
        //jTxtRegName.setText(null);
        jTxtRegFname.setText("");

        jDtRegDob.setDate(null);

        buttonGroup1.clearSelection();         // for button group radio button
        jRadioButton1.setSelected(false);     //for single radio button

        jChkRegMatric.setSelected(false);
        jChkRegInter.setSelected(false);
        jChkRegGrad.setSelected(false);
        jChkRegPg.setSelected(false);

        jTxtRegMobile.setText("");

        jTxtRegEmail.setText("");

        jCmbRegState.setSelectedIndex(0);
        //jCmbRegState.setSelectedItem("Patna");
        //jCmbRegState.removeAllItems();
        //jCmbRegState.removeItemAt(0);
        //jCmbRegState.removeItem("Bihar");

        jRtbRegAddress.setText("");

        jTxtRegUsername.setText("");
        jPdRegPasswd.setText("");

        // To clear jTable1 Data         
        import javax.swing.table.DefaultTableModel;

          ((DefaultTableModel)jTable1.getModel()).setNumRows(0); 
                     -----  OR  ------
          DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
          model.setRowCount(0);
                     -----  OR  ------
          DefaultTableModel dtm = (DefaultTableModel)jTable1.getModel();
          while (dtm.getRowCount()>0)
          {
             dtm.removeRow(0);
          }



        //jTxtRegName.grabFocus();
        jTxtRegName.requestFocus();
    }

NB : Call/Invoke the function at required place as clear();

Loading

Categories: Java Project

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.