Results 1 to 4 of 4
- 05-27-2010, 10:25 PM #1
Member
- Join Date
- May 2010
- Posts
- 5
- Rep Power
- 0
Use documentlistener to get source of which text field is changed
private class myListener implements DocumentListener
{
public void insertUpdate(DocumentEvent e)
{
// Hours
if(e.getSource() == hours)
{
String hours_text = hours.getText();
System.out.println(hours_text);
}
}
}
I need to be able to tell which text field the user inserts text into, so i used e.getSource() in an if statement to find if it was the hours text field. When I compiled I got an error saying could not find symbol.
- 05-27-2010, 10:58 PM #2
Senior Member
- Join Date
- May 2010
- Posts
- 436
- Rep Power
- 4
Possibly this is a scope issue and likely depending on the code that you're not showing us, but I can't really say for sure. Is hours declared in the constructor making it invisible to this inner private class?
Bottom line: we really need more information to be able to give accurate help. Also, if you use code tags when posting code here, it will be a lot easier to read your code.
Que tenga mucha suerte!Last edited by curmudgeon; 05-27-2010 at 11:01 PM.
- 05-28-2010, 02:32 AM #3
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
Even when you fix the compile problem is won't work, because the source is the Document, not the text field.
So you need to pass in the text field as a paramenter to your custom class when you create it.
Also, use the "Code tags" when you post code so the code you post retains its formatting and is readable.
- 05-28-2010, 04:18 AM #4
Member
- Join Date
- May 2010
- Posts
- 5
- Rep Power
- 0
I was able to solve the problem using this code
but I would like to know the idea Camickr had of passing the textfield as a parameter to my custom class would work out of curiosity. I tried to use your suggestion but was having trouble.Java Code:private class myListener implements DocumentListener { public void insertUpdate(DocumentEvent e) { if(e.getDocument() == hours.getDocument()) { System.out.println("Hello"); } }
Similar Threads
-
Text-field templates.
By jdipierro in forum New To JavaReplies: 4Last Post: 05-14-2010, 12:48 AM -
Refreshing Text Field Value
By nehakuls in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 11-13-2009, 11:05 AM -
Regarding Text Field
By adeeb in forum AWT / SwingReplies: 1Last Post: 06-05-2008, 11:01 PM -
Why the panel text changed?
By ottawalyli in forum AWT / SwingReplies: 1Last Post: 12-17-2007, 05:56 AM -
Why the panel text changed?
By ottawalyli in forum SWT / JFaceReplies: 0Last Post: 12-16-2007, 04:16 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks