Results 1 to 13 of 13
  1. #1
    Return 0 is offline Member
    Join Date
    Feb 2011
    Posts
    12
    Rep Power
    0

    Default Add custom icon to JOptionPane

    How do I place a custom icon on JOptionPane? I have the following:

    Java Code:
    JOptionPane.showMessageDialog( null, "Custom Icon", "ICON!!" , icon );
    I've tried a couple of different things based on my search results, but none of them have worked. Can someone provide me with some explicit instructions on how to get an icon up? Thanks.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,839
    Rep Power
    8

    Default

    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Return 0 is offline Member
    Join Date
    Feb 2011
    Posts
    12
    Rep Power
    0

    Default

    Quote Originally Posted by KevinWorkman View Post
    That's the tutorial I was following, but the examples never actually mention how to get an image associated with icon. I also looked at the API documentation but nothing was clear to me. I'm new to Java so I'm not sure where I should look.

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,839
    Rep Power
    8

    Default

    What have you actually tried? Where is the code where you create an Icon and pass it in to the method?

    Like I said, the API is your friend: JOptionPane (Java Platform SE 6)
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Return 0 is offline Member
    Join Date
    Feb 2011
    Posts
    12
    Rep Power
    0

    Default

    Quote Originally Posted by KevinWorkman View Post
    What have you actually tried? Where is the code where you create an Icon and pass it in to the method?

    Like I said, the API is your friend: JOptionPane (Java Platform SE 6)
    Yeah, Like I said, I looked at the API docs so you can stop linking me to other sites! Honestly it would have been so much easier for you to just drop this code and discuss it with me:

    Java Code:
            ImageIcon icon = new ImageIcon("C:\\Documents and Settings\\mit\\My Documents\\My Pictures\\img.gif");
    
            JOptionPane.showMessageDialog(null, "Custom", "Custom Image", JOptionPane.INFORMATION_MESSAGE, icon );
    I figured it out thanks anyway.

  6. #6
    Return 0 is offline Member
    Join Date
    Feb 2011
    Posts
    12
    Rep Power
    0

    Default

    Now I'm trying to use getResource to get the image path for the icon, but I'm getting a NullPointerException with the following:

    Java Code:
    ImageIcon icon = new ImageIcon( Driver.class.getResource( "\\src\\resources\\heart.gif" ) );
    
    JOptionPane.showMessageDialog(null, "Custom", "Test", JOptionPane.INFORMATION_MESSAGE, icon );
    The image is present. Am I using getResource incorrectly?

  7. #7
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,839
    Rep Power
    8

    Default

    Quote Originally Posted by Return 0 View Post
    Yeah, Like I said, I looked at the API docs so you can stop linking me to other sites! Honestly it would have been so much easier for you to just drop this code and discuss it with me:

    I figured it out thanks anyway.
    Wow, that's a pretty poor attitude. I linked you to two different places that tell you exactly what to do. You did not post any relevant (read: relevant) code, and then you expect me to just hammer it out for you. That's not really how this works.

    After that, I really don't feel like helping you any further. Much luck.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  8. #8
    Return 0 is offline Member
    Join Date
    Feb 2011
    Posts
    12
    Rep Power
    0

    Default

    Quote Originally Posted by KevinWorkman View Post
    Wow, that's a pretty poor attitude. I linked you to two different places that tell you exactly what to do. You did not post any relevant (read: relevant) code, and then you expect me to just hammer it out for you. That's not really how this works.

    After that, I really don't feel like helping you any further. Much luck.
    No it's not a poor attitude. People don't come to forums and post in a beginners section just to be directed to an API doc thousands of pages long on an API they don't know with zero direction. I didn't need to post any relevant code as I stated I did not know how to get an image as an icon, not that my code was defective. The API doc and tutorial did not specify.

    That's perfectly fine, I wasn't posting here looking for your help after the responses I've received from you thus far. I appreciate the time people take out of their lives to assist others on forums, but not when someone just redirects you because it defeats the purpose of the damn forum.

    You did the same crap on my other post where I asked how to go about distributing my application with such helpful comments like:

    "Methinks you're looking for an executable jar. "
    and
    "Sounds like the work of witchcraft to me."

    just racking up your post count...

    I guess my time in this forum will be quite short lived!

  9. #9
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,839
    Rep Power
    8

    Default

    I did not post a link to the general API. I posted a link to the specific method to use to get a custom Icon in a message dialog. I'm not sure what else you want, other than for somebody to write the code for you.

    If you had actually looked at the link instead of whining about it, you could have posted the code you were attempting to run, and I could have looked at it and told you what you were doing wrong. Instead, you chose to whine because you weren't spoonfed code- even though both links I gave you contain pretty much exactly the line you're looking for.

    Your other question was "how do I send a project and have it be runnable?" or something to that effect. I gave you a jumping off point, a term to google, something to investigate. Had you asked a more specific question, I could have provided a more specific answer.

    And the comment about witchcraft was just a joke, after you said your problem was fixed by recompiling.

    You will not be receiving help from me in the future after these childish outbursts. I predict your career as a programmer would be "short lived" also, if your attitude towards basic googling and reading of documentation is "aw but I don't wanna!"
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  10. #10
    Return 0 is offline Member
    Join Date
    Feb 2011
    Posts
    12
    Rep Power
    0

    Default

    Quote Originally Posted by KevinWorkman View Post
    I did not post a link to the general API. I posted a link to the specific method to use to get a custom Icon in a message dialog. I'm not sure what else you want, other than for somebody to write the code for you.

    If you had actually looked at the link instead of whining about it, you could have posted the code you were attempting to run, and I could have looked at it and told you what you were doing wrong. Instead, you chose to whine because you weren't spoonfed code- even though both links I gave you contain pretty much exactly the line you're looking for.

    Your other question was "how do I send a project and have it be runnable?" or something to that effect. I gave you a jumping off point, a term to google, something to investigate. Had you asked a more specific question, I could have provided a more specific answer.

    And the comment about witchcraft was just a joke, after you said your problem was fixed by recompiling.

    You will not be receiving help from me in the future after these childish outbursts. I predict your career as a programmer would be "short lived" also, if your attitude towards basic googling and reading of documentation is "aw but I don't wanna!"
    Yeah yeah whatever. Looking at your posting history confirmed what I was saying. I looked at the link and again, all it does is provide some details on the method, it DOES NOT indicate how to get an icon associated with an image.

    Parameters:
    parentComponent - determines the Frame in which the dialog is displayed; if null, or if the parentComponent has no Frame, a default Frame is used
    message - the Object to display
    title - the title string for the dialog
    messageType - the type of message to be displayed: ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE
    icon - an icon to display in the dialog that helps the user identify the kind of message that is being displayed

    See that line that says icon? That doesn't help at all, just tells me there's a parameter.

    How do you think I found the damn solution? By using google and reading documentation you idiot! My career as a programmer would be short lived? lol I hate to break it to you pal, but I've been a C++/ASM Developer for 12 years now.

  11. #11
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,839
    Rep Power
    8

    Default

    You've been a programmer for 12 years and you still don't know how to ask a specific question? And you still react like a teenager when confronted with some blunt advice?

    Your first post made it seem like you were unfamiliar with the method. Saying "I tried a few different things" is completely vague, and I took it to mean that you didn't know what the parameters meant, etc. Had you provided some actual code (your question was apparently about how to instantiate an Icon, yet you did not post your attempts at doing so), or even described the actual problem ("none of them worked" isn't describing a problem), I could have provided a more specific answer. However, since you asked a vague question, the best anybody can do is to point you towards documentation and tutorials.

    If that wasn't enough, you could have posted a real question- with an SSCCE, or at least some actual code, and an actual description of the problem. Were you getting an Exception? Compiler errors? Weird behavior? Something else? Do you see where I'm going with this?

    Resorting to calling me an idiot after I tried to help you despite you making no effort to ask a real question is one way to make sure that not only I, but others around here, don't help you in the future.

    I know you hate links and reading, but I suggest you read the link in my signature on asking smart questions.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  12. #12
    Lethedethius is offline Member
    Join Date
    Jan 2012
    Posts
    3
    Rep Power
    0

    Default Re: Add custom icon to JOptionPane

    *Slaps table out of laughter*

    Return 0 I'm a noob programmer and I can ask a proper question, if you don't know what your doing just post your source and let someone correct, it's not secret squirrel bro. If it is secret squirrel highly classifed stuff I'm pretty sure you'll be fired for just not knowing your job *lmao*, either way your problem will be solved. Maybe apologize and ask for help guy :)

    Kevin, you related to a Thomas Workman in Columbus/Lancaster Ohio?

  13. #13
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,839
    Rep Power
    8

    Default Re: Add custom icon to JOptionPane

    Quote Originally Posted by Lethedethius View Post
    *Slaps table out of laughter*

    Return 0 I'm a noob programmer and I can ask a proper question, if you don't know what your doing just post your source and let someone correct, it's not secret squirrel bro. If it is secret squirrel highly classifed stuff I'm pretty sure you'll be fired for just not knowing your job *lmao*, either way your problem will be solved. Maybe apologize and ask for help guy :)

    Kevin, you related to a Thomas Workman in Columbus/Lancaster Ohio?
    Eh, this post is way old, so the original poster is long gone. Thanks for the support though.

    And I'm not sure, maybe! I'm from Lancaster, Pennsylvania originally. I'm not too familiar with my extended family.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Custom Icon Demo
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-23-2008, 11:19 PM
  2. icon
    By amith in forum AWT / Swing
    Replies: 1
    Last Post: 05-16-2008, 07:34 PM
  3. Custom icon for Frame
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-21-2007, 08:38 AM
  4. Changing icon of JOptionPane
    By mew in forum New To Java
    Replies: 3
    Last Post: 12-21-2007, 07:01 AM
  5. Replies: 0
    Last Post: 12-17-2007, 09:46 AM

Posting Permissions

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