Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Incompatible types.

  1. #1
    Member
    Join Date
    Jan 2013
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Incompatible types.

    Hi my code is showing incompatible types with my JTextField. Is this not the correct way to do it?

     if(SearchField.equals("Stapler"))

    This is for my button. SearchField = JTextField. The equals in the () is showing up as an incompatible type.

    What should i do to correct it.


  2. #2
    Member
    Join Date
    Feb 2012
    Posts
    173
    Thanks
    6
    Thanked 10 Times in 10 Posts

    Default Re: Incompatible types.

    Strings are not JTextFields, you need to get what's in the text field to compare with a String.

  3. #3
    Member
    Join Date
    Jan 2013
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Incompatible types.

    How would i do that? I need to be able to type in a string in the SearchField and when it equals lets say Stapler i need it to show some information. how do i get whats in the JTextField to compare with a string?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Incompatible types.

    how do i get whats in the JTextField to compare with a string?
    Read the API doc for the JTextField class and find the method that will get the String that is int the text field.
    Java Platform SE 7
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Jan 2013
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Incompatible types.

    Thanks norm i know its in there somewear and i looked but i cannot find it. Can you narrow it down some?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Incompatible types.

    This one is a little more difficult than usual. The JTextField class extends a class that has the method you are looking for. And that class extends another class which has more methods etc.

    Look at all the methods that return a String.

    Also the first part of the doc has a link that has examples:
    How to Use Text Fields (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    Jan 2013
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Incompatible types.

    Thank you very much. I have another problem. Should i make a new thread or continue on using this one?

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Incompatible types.

    If its a new problem, start a new thread with a new title.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Incompatible types
    By jadeclan in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 26th, 2012, 07:09 AM
  2. Incompatible types
    By jadeclan in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 25th, 2012, 04:44 PM
  3. incompatible types!!
    By sneha343 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 30th, 2011, 05:48 PM
  4. incompatible types
    By frozen java in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 25th, 2011, 10:40 AM
  5. Incompatible Types
    By Kimimaru in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 28th, 2010, 09:52 AM