Results 1 to 4 of 4
  1. #1
    jdg951 is offline Member
    Join Date
    Dec 2010
    Posts
    7
    Rep Power
    0

    Default Displaying error message if no text found

    I made a GUI that searches text in a JTextArea, but I want it to display an error message if there is no text in the search JTextField and the Target JTextArea... I figured my current code would have worked, but I guess not...

    Any help will be much appreciated.

    Java Code:
    else if(caption.equals("Search"))
    			{
    				if(jtaTarget.getText() == "")
    				{
    					JOptionPane.showMessageDialog(null, "Target TextArea is empty");
    				}
    				else if(jtfSearch.getText() == "")
    				{
    					JOptionPane.showMessageDialog(null, "Search TextField is empty");
    				}
    			}
    Last edited by jdg951; 01-17-2011 at 10:50 PM.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,784
    Rep Power
    7

    Default

    "it doesn't work" provides zero information.

    Try using methods instead of using == to compare objects.

  3. #3
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default

    Use equals() rather than == when comparing objects (in this case comparing 2 Strings)

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,784
    Rep Power
    7

    Default

    Wow, I just noticed this:
    Java Code:
    else if(caption.equals("Search")) {
        if(jtaTarget.getText() == "")

Similar Threads

  1. Displaying text in a JPanel
    By DrKilljoy in forum New To Java
    Replies: 7
    Last Post: 04-15-2011, 07:28 PM
  2. Displaying text in a tabel
    By pele in forum SWT / JFace
    Replies: 5
    Last Post: 05-28-2008, 07:05 AM
  3. Strange error message "Source not found"
    By ppayal in forum Eclipse
    Replies: 0
    Last Post: 11-25-2007, 06:19 PM
  4. Displaying text box on MIDlet form
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-22-2007, 10:06 AM
  5. Urgent-Imp-Displaying message with respect to system time
    By garinapavan in forum New To Java
    Replies: 1
    Last Post: 08-03-2007, 02:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •