aspose file tools*
The moose likes Beginning Java and the fly likes Text Filed Problem? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Text Filed Problem?" Watch "Text Filed Problem?" New topic
Author

Text Filed Problem?

lakmal padmakumara
Ranch Hand

Joined: Aug 08, 2009
Posts: 47
I have a Text Field in my Jframe. Is there any Exception which throws it self when we called textfiled.getText() without entering anything in it .
What I want to do is if the user does not input anything on the text field and press "OK "button it should throw an Exception.Is there any way to do this ?


[Bsc in Computer Science and Engineering] [SCJP 80%][BCS certificate level]
Jeff Yan
Ranch Hand

Joined: Nov 05, 2009
Posts: 42
id use an IOException! what is your code like?
you need to put try before you catch the exception or declare it at the beggining after the method by saying throws IOException e.g. :

import java.io.*;


public void readFile() throws IOException
{
try
{
//do whatever it is that you do in your method
}catch (IOException e)
{
System.out.println("Unknown error has occured!");
}
}


hope that helped!


~ Jeff Yan ~
John de Michele
Rancher

Joined: Mar 09, 2009
Posts: 600
Jeff:

Actually, IOException is better used in instances where you're dealing with system IO. IllegalArgumentException is probably a better fit.

John.
Jeff Yan
Ranch Hand

Joined: Nov 05, 2009
Posts: 42
very true! i think your right there.
Victor Ewert
Greenhorn

Joined: May 28, 2009
Posts: 17
If you are simply trying to let the user know they must enter something into the TextField, then when you use getText(), check if the length of the returned String is > 0, and if it isn't then display a warning message to the user.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Text Filed Problem?