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.

Page 3 of 3 FirstFirst 123
Results 51 to 61 of 61

Thread: Help with checking JButton positions please

  1. #51
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help with checking JButton positions please

    that still doesn't work,
    Please explain.

    Why use client properties when the class has a method you can call directly to determine if it has an image: see the icon get and set methods for the class.
    If you don't understand my answer, don't ignore it, ask a question.

  2. #52
    Member
    Join Date
    Oct 2012
    Posts
    68
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Help with checking JButton positions please

    I have already set the button to have an ImageIcon though, I just need to know how I can tell if it has an image or not,

    say I have two buttons I click on one, and I want to know if the left of that button has an image?

  3. #53
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help with checking JButton positions please

    how I can tell if it has an image or not,
    Call the method that will return the image if it has one. Read the API doc for the JButton class and see what method returns the current icon/image that the object is using.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #54
    Member
    Join Date
    Oct 2012
    Posts
    68
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Help with checking JButton positions please

    I have looked at the API, and I can only find checkImage(), but not sure how to use it in this context :/ ?
    Thanks for all your help again

  5. #55
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help with checking JButton positions please

    Your code uses the setIcon() method to set the image.
    Look at the getIcon() method for getting the image that was set with the setIcon() method.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #56
    Member
    Join Date
    Oct 2012
    Posts
    68
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Help with checking JButton positions please

    I have tried:

                System.out.println("There is an image!");
            }

    But I get a nullPointerExceptionError?

  7. #57
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help with checking JButton positions please

    I get a nullPointerExceptionError
    What variable is null? Where does the code assign a non-null value to the variable?
    See posts #49 and 43. Make sure the code is not using a variable that is local to a method.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #58
    Member
    Join Date
    Oct 2012
    Posts
    68
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Help with checking JButton positions please

    it assigns a null value to the 'leftbtn', I just can't seem to get it :/

  9. #59
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help with checking JButton positions please

    That means that the button array has a null value. Why does the button array have a null value?

    See posts #49 and 43. Make sure the code is not using a variable that is local to a method.
    How many variables named: button are defined in the code?
    Which one has values assigned to it?
    Which one NEVER has values assigned to it and will contain null entries?
    If you don't understand my answer, don't ignore it, ask a question.

  10. The Following User Says Thank You to Norm For This Useful Post:

    sim18 (December 4th, 2012)

  11. #60
    Member
    Join Date
    Oct 2012
    Posts
    68
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Help with checking JButton positions please

    THANK YOU SOOOOOOOO MUCH!
    You have made my day!!!

  12. #61
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help with checking JButton positions please

    Glad you found it. I don't know why IDEs don't give warnings when variable definitions shadow other definitions.
    If you don't understand my answer, don't ignore it, ask a question.

Page 3 of 3 FirstFirst 123

Similar Threads

  1. help to checking the error!!
    By vitorloke in forum Java Theory & Questions
    Replies: 12
    Last Post: April 27th, 2012, 09:46 AM
  2. Checking Blurbs
    By 9erNumber16 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 7th, 2011, 07:29 PM
  3. Need help with checking passwords
    By kb1213 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: April 12th, 2011, 05:32 PM
  4. Checking in.
    By Johannes in forum Member Introductions
    Replies: 7
    Last Post: August 13th, 2009, 06:11 AM
  5. [SOLVED] Getting Exception " java.util.InputMismatchException" in scanner package
    By luke in forum File I/O & Other I/O Streams
    Replies: 10
    Last Post: May 20th, 2009, 04:55 AM