Since you haven't provided any code it is difficult to say. However you can try the following: 1)Looks like you are trying to trap what the user has typed and take some decisions accordingly.In that case you can use DocumentListener instead of KeyListener 2)Looks like you are trying to do some validation when the component gains/looses focus.In that case you can use the InputVerifier instead of the focus listener 3)Looks like you are using the MouseListener to display the popup menu. If you are using 1.5+ you can use the setComponentPopupMenu() method.
Please note I am just shooting in the dark here, as you haven't provided any code.
Hi Maneesh thank you very much for the early reply. I use popup menu to get copy past and cut commands. But when i write something and select some text to copy then i write click the mouse to get the popup menu to select copy command the earlier selected text is no longer highlighted. So it passes null to copy and doesn't do anything. That is because when i press the mouse again focus listener takes place. What i want is to keep the selected text till it calls my popup listener. I'm sorry I have no idea that which part of my code to send you as it is too long. If you can tell me the part you want to give a solution I'll send you soon. Thank you
Drop the mouse and focus listeners. You dont need them. Try with the setComponentPopup method I mentioned.
Joined: Apr 18, 2008
Hi. The person who worked with this code earlier had added this focus listener to do some sort of validation. So it is needed to keep that listener as i do not have permission to modify the previous code. So if i use the setComponentPopupMenu method, again i need the selected text. But because of the focus listener i'm unable to do it. So i need a way to select text without removing the focus listener thank you.
You mean to switch in to InputMethodListener. No I'm unable to do that. Because the previous guy has implemented focus listener methods in another class and here also he has done it as follows FormatAction formatAction = new FormatAction(); nameTextField.addFocusListener( formatAction );
NameFormatAction class is the place where he has implemented focus listener methods and if I changed it to another listener, classes that are using NameFormatAction also has to be changed and it 'll be a big issue.
Add a mouse listener. On mouseEntered you remove the focus listener and on mouseExited you add it again.
Anyone else got any better ideas?
Joined: Apr 18, 2008
Hi With the permission I've changed the old code. Removed KeyListener and Focus Listener and added the DocumentListener as you said. Now it is working properly. Thank you very much for the great great help. Again Thanks a lot