• Post Reply Bookmark Topic Watch Topic
  • New Topic

AWT - Help needed  RSS feed

 
pratik_khetia
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a situation where I need to have a functionality to put a textfield anywhere on the applet ...on MousePressed event...
How do I do that ?
I would appriciate if anybody can write me a reply..
thanks
Pratik
 
Gary Bryan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to set the layout manager to null, add the textfield to the container you want it on, then use the setLocation method to set its position.
(on the container you want)
TextField tf;
...
tf = new TextField(10);
add(tf);
setLayout(null);
...
public void mousePressed(MouseEvent e) {
tf.setLocation(50, 50);
}
would set the location of the textfield's top-left corner to 50,50.
If you want to set it to where the mouse was clicked, use
tf.setLocation(e.getPoint());
Hope this helps.
 
pratik_khetia
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
I think it should work..I'll try that and get back to u again..

bye
Pratik
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"pratik_khetia",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.
Thanks.
 
pratik_khetia
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gary,
For that AWT help...I tried that..but it's not letting me do that..now let me write u the details...
I am using Swing & JDK1.3 now in my applet the layout is something like this..
container cPane = getContentPane();
cPane.add(JSP,CENTER) (JSP is a JScrollPane)
cPane.add(toolbar,SOUTH) (toolbar is a JToolbar)
Now I am using a JEditorPane which is inside the JScrollPane..and on that I want to put a textbox anywhere I click the mouse...
So I tried as u said but it's now working...though it's not giving any errors too !So if I want to keep my layout intact..how should I do ..?
any help from u would be higly appriciated
thanks
Pratik Khetia
Originally posted by Gary Bryan:
You need to set the layout manager to null, add the textfield to the container you want it on, then use the setLocation method to set its position.
(on the container you want)
TextField tf;
...
tf = new TextField(10);
add(tf);
setLayout(null);
...
public void mousePressed(MouseEvent e) {
tf.setLocation(50, 50);
}
would set the location of the textfield's top-left corner to 50,50.
If you want to set it to where the mouse was clicked, use
tf.setLocation(e.getPoint());
Hope this helps.

 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have the 1.3 plug-in that allows your browser to use swing?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!