[4572] in java-interest

home help back first fref pref prev next nref lref last post

Re: Placing a textfield

daemon@ATHENA.MIT.EDU (Arthur van Hoff)
Sun Jan 7 16:24:06 1996

From: Arthur.Vanhoff@Eng.Sun.COM (Arthur van Hoff)
To: mikea@ai.mit.edu (Michael Afergan)
Date: Sun, 7 Jan 1996 12:05:06 -0800 (PST)
Cc: java-interest@webrunner.neato.org (java)
In-Reply-To: <9601071918.AA26699@life.ai.mit.edu> from "Michael Afergan" at Jan 7, 96 02:13:57 pm


Hi Mike,

> 	Am I missing something or is there no real nice way of placing a 
> java.awt.Textfield in an applet?  I would expect a constructor such as 
> Textfiled(x,y), but that isn't the way the class is set up.  Is there some way 
> of doing this through the pannel class?
> 	Any suggestions and advice would be greatly appreciated.

That is actually quite easy. You can simply write:

	TextField txt;

	public void init() {
	    txt = new TextField();
	    add("Center", txt);
	}

An applet is a panel with a BorderLayout. Adding the text field as the
center component will make sure that it fills the entire space of the
applet.

To move it around you first have to set the layout for the applet to
null, and then you can use:

	public void init() {
	  setLayout(null);
	  txt = new TextField();
	  txt.reshape(10,10,100,30);
	}

You should to avoid using absolute layout though.

Have fun,

	Arthur van Hoff (avh@eng.sun.com)
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post