Wednesday, November 16, 2011

JTextField Show Hide

    package org.best.example;
    /*
            JTextField Show Hide Example
            This java example shows how to show or hide JTextField
            using Java Swing JTextField class.
    */
    
    
    import java.awt.FlowLayout;
    import javax.swing.JApplet;
    import javax.swing.JTextField;
    
    /*
    <applet code="JTextFieldShowHideExample" width=200 height=200>
    </applet>
    */
    public class JTextFieldShowHideExample extends JApplet{
    
            public void init(){
                  
                    //set flow layout for the applet
                    this.getContentPane().setLayout(new FlowLayout());
    
                    //create new JTextField
                    JTextField field = new JTextField("JTextField Show Hide Example", 10);
                  
                    /*
                     * To hide JTextField use
                     * void setVisible(boolean visible)
                     * method with false argument.
                     */
                  
                    field.setVisible(false);
                  
                    /*
                     * To set the hidden JTextField visible, use the same method
                     * with the true argument.
                     */
                  
                    //field.setVisible(true);
                  
                    add(field);
            }
    }

No comments: