Here you can find the source of createJTextField(Container c, String text, int x, int y, int width)
JTextField
and adding it to its container class.
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 |
JTextField
instance
public static JTextField createJTextField(Container c, String text, int x, int y, int width)
//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; } }