Java JTextField Create createJTextField(Container c, String text, int x, int y, int width)

Here you can find the source of createJTextField(Container c, String text, int x, int y, int width)

Description

This method makes it easy (and also neat) creating a JTextField and adding it to its container class.

License

Open Source License

Parameter

Parameter Description
c the container
text the text to be shown
x x of its upper left corner
y y of its upper left corner
width width of the component

Return

a JTextField instance

Declaration

public static JTextField createJTextField(Container c, String text, int x, int y, int width) 

Method Source Code

//package com.java2s;
/*//from   www  . ja v  a 2s  . c  o  m
 This file is part of Coach Assistant
 Copyright (C) 2004-2006 Sina Iravanian  <sina_iravanian@yahoo.com>
    
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; version 2 of the License.
    
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
    
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

import java.awt.Container;

import javax.swing.JTextField;

public class Main {
    /**
     * This method makes it easy (and also neat) creating a
     * <code>JTextField</code> and adding it to its container class.
     * <p>
     * The <code>BorderLayout</code> of the container class must be set to
     * <code>null</code>.
     * 
     * @param c
     *            the container
     * @param text
     *            the text to be shown
     * @param x
     *            x of its upper left corner
     * @param y
     *            y of its upper left corner
     * @param width
     *            width of the component
     * @return a <code>JTextField</code> instance
     */
    public static JTextField createJTextField(Container c, String text, int x, int y, int width) {
        JTextField txt = new JTextField(text);
        txt.setBounds(x, y, width, 20);
        c.add(txt);
        return txt;
    }
}

Related

  1. createJTextField(Rectangle bounds)
  2. createJTextField(String name, int value, FocusListener fl)
  3. initJTextField(JTextField text, String element)
  4. initLabelComponent(final JLabel label, final JTextField textField)