|
-
January 27th, 1999, 05:26 PM
#1
.requestFocus() does not seem to work?
I can't get the .requestFocus() for a component to work.
I'd like to have the cursor on a particular input field when the dialog opens, so I call the Component.requestFocus() as the last thing in the dialog init method, but it doesn't work!
What am I missing?
P.S This is all Swing 1.1 stuff.
Thanks.
-
May 18th, 1999, 06:52 AM
#2
Re: .requestFocus() does not seem to work?
Request focus will work for controls like you can give as given below
suppose let us assume that you are having a button and you have also written an event to it
in that event write the code like this
TextField t=new TextField(10);
add(t);
t.requestFocus()
create an object for text field add it to you component and give request focus
it will work and it also works for text area
my name is viji and i am working in ssi
-
May 18th, 1999, 08:56 PM
#3
Re: .requestFocus() does not seem to work?
I find that using this method will set the focus in the JTextfield but the cursor will not blink initially.
-
May 27th, 1999, 11:27 AM
#4
Re: .requestFocus() does not seem to work?
Probably you are missing this line "setRequestFocusEnabled(true)" before you call "requestFocus()".
This according to the documentation, should not be necessary, as the "setRequestFocusEnabled" is defaulted to be true. But still try and see if it works.
Thanks and Regards
Amaresh
-
May 31st, 1999, 06:14 AM
#5
Re: .requestFocus() does not seem to work?
This seems to be a problem in Swing at the moment. I encountered the same thing: the JTextFiels has focus so you type text in it, but you don't see any cursor blinking. I don't know a solution to this. Any help would be great!
-
May 31st, 1999, 09:05 AM
#6
Re: .requestFocus() does not seem to work?
Request Focus works finely if the entire control is created fully and displayed. Suppose if u r trying to put the focus on a component in a applet or a dialog or any container... instead of writing the code in the init write the same code in the start of the container. I mean if u write this in the init of the applet it will never work.. If u try this in the start of the applet it will work finely.. Infact worked finely to me.
Suppose if u r doing the same for frame or dialog u have call the request focus after creating the dialog completely.
thanks lot,
Srini
-
June 2nd, 1999, 10:15 AM
#7
Re: .requestFocus() does not seem to work?
Well, there are two issues here. One is focus and the other one is cursor blinking.
I guess the default cursor is "pointer with arrow tip". You need to change the cursor to "text Cursor" if you want to see cursor blinking.
To summarize, you need to do the following things on a non-focussed text field in-order to get focus and see the cursor blinking.
1) Change the cursor to "Text Cursor". You need to do something like the following:
m_myTextField.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.TEXT_CURSOR));
2) Call "requestFocus()"
I hope this helps.
Thanks,
Amaresh
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|