How to Prefill the TextBox From Webpage in Java

A text box is a section or field of a Web page that allows a user to input free text. Text boxes are primarily used on websites that require text input from visitors. There are various types of text boxes, such as one-line text box or scrolling text box. With Java, you can prefill a text box on your Web page as users type their input. Java's intuitive applications make it a preferred choice by programmers for creating Web components.

Instructions

    • 1

      Paste the following code to import the Java Preferences package:

      import java.util.prefs.*;

      Insert the code below to create a reference to your Java Preferences:

      // declare my variable at the top of my Java class

      private Preferences prefs;

      // create a Preferences instance (somewhere later in the code)

      prefs = Preferences.userNodeForPackage(this.getClass());

    • 2

      Paste the succeeding code to set the preference when a desired action takes place:

      void outputDirectoryButton_actionPerformed(ActionEvent e)

      {

      int status = getDirectoryFromUser(jFileChooser,mostRecentOutputDirectory);

      if ( status == JFileChooser.APPROVE_OPTION )

      {

      mostRecentOutputDirectory = jFileChooser.getSelectedFile();

      jspOutputDirectoryTextField.setText(mostRecentOutputDirectory.getAbsolutePath());

      prefs.put("LAST_OUTPUT_DIR", mostRecentOutputDirectory.getAbsolutePath());

      }

      }

    • 3

      Input the following code to enable the reference that will prepopulate or prefill your text box when the user starts entering text on the data entry screen of your Web page:

      String lastOutputDir = prefs.get("LAST_OUTPUT_DIR", "");

      outputDirectoryTextField.setText(lastOutputDir);

Tips & Warnings

  • Free tutorials abound online for Java, so learn as many as you can to get a basic knowledge of this useful technology. Spice up your website with the many cool effects of Java.

Related Searches:

References

Resources

Comments

Related Ads

Featured