4 Replies Latest reply: Apr 14, 2008 12:35 PM by 807601 RSS

    clearing text fields and resetting?

    807601
      How would I go about clearing all my input text fields and resetting the cursor to the top box when my button is clicked?

      - GoOsE
        • 1. Re: clearing text fields and resetting?
          807601
          [Problem Report Standard Litany|http://homepages.tesco.net/~J.deBoynePollard/FGA/problem-report-standard-litany.html]. We have no idea if you're talking about Swing/AWT/HTML/SWT/etc.

          ~
          • 2. Re: clearing text fields and resetting?
            807601
            That is to clear a text field
            jTextField1.setText("");
            • 3. Re: clearing text fields and resetting?
              807601
              the button click is handled by ActionListener interface. So inside the function actionPerformed(), you can set all your text fields to empty strings as
              tf1.setText("");
              I am not sure abt the cursor resetting tho

              The problem you mentioned is quite similar to the one i am having. i am writing a calculator applet with a number of buttons and a text field. After the input of first number, i want to reset the text fiels so that whatever numeral is next entered is treated as a new string. Keep in mind that i dont want to set the text field text as an empty string for the meantime. It must continuously show the last input number or result as in windows calculator

              Can anyone help me with this.

              Edited by: aytidaalkuhs on Apr 14, 2008 10:24 AM

              Edited by: aytidaalkuhs on Apr 14, 2008 10:24 AM
              • 4. Re: clearing text fields and resetting?
                807601
                aytidaalkuhs wrote:
                The problem you mentioned is quite similar to the one i am having. i am writing a calculator applet with a number of buttons and a text field. After the input of first number, i want to reset the text fiels so that whatever numeral is next entered is treated as a new string. Keep in mind that i dont want to set the text field text as an empty string for the meantime. It must continuously show the last input number or result as in windows calculator
                Check the Javadoc for JTextComponent#getDocument()#insertString()