Results 1 to 7 of 7
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: Adding an image/icon to Jpanel?

  1. #1
    Jpyo is offline Member
    Join Date
    Apr 2012
    Posts
    1
    Rep Power
    0

    Default Adding an image/icon to Jpanel?

    Hi guys,

    For one of my assignments I have to put graphics/icons/picture into my panel and I don't know how... I looked at other java forums and tried using their examples but it doesn't work? (or I'm just placing it in the wrong spot, I can't tell..)

    Firstly, I'm making an E-mail thing so when the user types to, subject, body and click send, if successful a JLabel will appear and say "Email sent" I also wanted it to show a smiley face and I used the example in my book (as well as other people's suggestions)
    Java Code:
    ImageIcon happyIcon = new ImageIcon("Happy.jpg");//from book
    lblEmailSent.setIcon(happyIcon); //from book
    lblEmailSent.setText("Email Sent");
    I did this ^ and then my "Email Sent" label turned completely white when I ran it so yeah, Any suggestions ?

    I'm not sure if my placement is wrong but my tutor said to place it where I wanted it to be seen which is when "Email Sent" shows up.

    Thanks.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,404
    Rep Power
    20

    Default Re: Adding an image/icon to Jpanel?

    To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem.

    Make sure you limit the SSCCE to code that's involved in your problem. We don't want to see code that sends an email or anything unrelated.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Ksammie01 is offline Member
    Join Date
    Apr 2012
    Posts
    8
    Rep Power
    0

    Default Re: Adding an image/icon to Jpanel?

    i would suggest that you use a message box to indicate that the email has been sent.
    you what you do, you declare a string, and then place the string on a message box..
    try {
    String s = "Logged in";
    JOptionPane.showMessageDialog(null,s);
    String url3 = "https://twitter.com";
    java.awt.Desktop.getDesktop().browse(java.net.URI. create(url3));
    System.exit(ABORT);
    }
    this a piece of code that is behind a button that logs you into some app i created, so the "logged in" is displayed on the message box, and then when you press ok, you are redirected to the twitter website.
    hope it helps.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,404
    Rep Power
    20

    Default Re: Adding an image/icon to Jpanel?

    @Ksammie01: BB Code List - Java Programming Forum

    Also, try not to make a habit of posting code solutions without seeing what the questioner already knows. You may be wasting your time; on the other hand, you may be spoonfeeding. On a forum, filling the knowledge gaps is more useful than either.

    However, in this case, the question is not about showing a modal dialog, so your response is wildly off the mark. Rather, the question is about updating a JLabel that (regardless of where in the GUI it is placed) possibly functions like a status bar in many applications.

    db
    Ksammie01 likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    Ksammie01 is offline Member
    Join Date
    Apr 2012
    Posts
    8
    Rep Power
    0

    Default Re: Adding an image/icon to Jpanel?

    ok..now i tried to do something like yours but it also doesn't work..
    putting/displaying text on a label like say if a button is pressed..
    i don't know why, did you succeed?

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,404
    Rep Power
    20

    Default Re: Adding an image/icon to Jpanel?

    If you have a question, start your own thread, they're free. Don't hijack another poster's thread with questions of your own.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #7
    Ksammie01 is offline Member
    Join Date
    Apr 2012
    Posts
    8
    Rep Power
    0

    Default Re: Adding an image/icon to Jpanel?

    Quote Originally Posted by DarrylBurke View Post
    If you have a question, start your own thread, they're free. Don't hijack another poster's thread with questions of your own.

    db
    i wasn't trying to hijack, i was trying to find a solution to his problem so i these things are actually related..
    but if you call it hijacking, i will start a new thread

Similar Threads

  1. Adding a jpanel to a customized Jpanel Class
    By trishtren in forum AWT / Swing
    Replies: 7
    Last Post: 04-05-2011, 06:52 PM
  2. Adding another icon to an icon
    By whateverme in forum New To Java
    Replies: 11
    Last Post: 03-29-2011, 08:00 PM
  3. Adding Jpanel ontop of another Jpanel
    By Manfizy in forum AWT / Swing
    Replies: 4
    Last Post: 03-05-2011, 10:34 PM
  4. adding a buffered image over a jpanel
    By fatmat9 in forum New To Java
    Replies: 1
    Last Post: 11-23-2010, 03:23 AM
  5. Image icon in SWT
    By ashin in forum SWT / JFace
    Replies: 3
    Last Post: 07-11-2009, 02:21 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
  •