Skip to Content

Create New JTextField Example

  • strict warning: Non-static method view::load() should not be called statically in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/views.module on line 906.
  • strict warning: Declaration of views_handler_argument::init() should be compatible with views_handler::init(&$view, $options) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_argument.inc on line 0.
  • strict warning: Declaration of views_handler_filter::options_validate() should be compatible with views_handler::options_validate($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter.inc on line 0.
  • strict warning: Declaration of views_handler_filter::options_submit() should be compatible with views_handler::options_submit($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter.inc on line 0.
  • strict warning: Declaration of views_handler_filter_boolean_operator::value_validate() should be compatible with views_handler_filter::value_validate($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter_boolean_operator.inc on line 0.
  • strict warning: Declaration of views_plugin_style_default::options() should be compatible with views_object::options() in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_style_default.inc on line 0.
  • strict warning: Declaration of views_plugin_row::options_validate() should be compatible with views_plugin::options_validate(&$form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_row.inc on line 0.
  • strict warning: Declaration of views_plugin_row::options_submit() should be compatible with views_plugin::options_submit(&$form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_row.inc on line 0.

  1. /*
  2.         Create New JTextField Example
  3.         This java example shows how to create new JTextField using
  4.         Java Swing JTextField class.
  5. */
  6.  
  7.  
  8. import java.awt.FlowLayout;
  9.  
  10. import javax.swing.JApplet;
  11. import javax.swing.JTextField;
  12.  
  13. /*
  14. <applet code="CreateNewJTextFieldExample" width=200 height=200>
  15. </applet>
  16. */
  17.  
  18. public class CreateNewJTextFieldExample extends JApplet{
  19.  
  20.         public void init(){
  21.                
  22.                 //set flow layout for the applet
  23.                 this.getContentPane().setLayout(new FlowLayout());
  24.                
  25.                 /*
  26.                  * To create new JTextField use,
  27.                  * JTextField()
  28.                  * constructor.
  29.                  *
  30.                  * This will create new empty JTextField.
  31.                  */
  32.                
  33.                 JTextField field1 = new JTextField();
  34.                
  35.                 /*
  36.                  * To create new JTextField with default text, use
  37.                  * JTextField(String text)
  38.                  * constructor.
  39.                  *
  40.                  * This will create new JTextField with default text.
  41.                  */
  42.                 JTextField field2 = new JTextField("JTextField Default Text");
  43.                
  44.                 /*
  45.                  * To create new JTextField with specified number of columns, use
  46.                  * JTextField(int columns)
  47.                  * constructor.
  48.                  *
  49.                  * This will create new empty JTextField with specified number of
  50.                  * columns.
  51.                  */
  52.                 JTextField field3 = new JTextField(10);
  53.                
  54.                 /*
  55.                  * To create new JTextField with default text and columns use
  56.                  * JTextField(String text, int columns)
  57.                  * constructor.
  58.                  *
  59.                  * This will create new JTextField with default text and specified
  60.                  * number of columns.
  61.                  */
  62.                 JTextField field4 = new JTextField("JTextField Default Text", 20);
  63.                
  64.                 /*
  65.                  * Add text field to the applet
  66.                  */
  67.                 add(field1);
  68.                 add(field2);
  69.                 add(field3);
  70.                 add(field4);
  71.                
  72.         }
  73. }