Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8812715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:40:03+00:00 2026-06-14T03:40:03+00:00

It seems like i’m not the only one with that question but I can’t

  • 0

It seems like i’m not the only one with that question but I can’t find an answer that solves the problem.

I created a Label and assign an Icon to it using WYSIWYG interface designer.
Now I want to change the icon dynamically during runtime.

The logic way would be like this (my first attempt) :

ImageIcon newIcon = new ImageIcon("SomePath");
jLabel1.setIcon(newIcon); 

When I do this the Icon simply disapears from the interface so I googled it and someone said to “flush” the icon whatever this means I tried it :

ImageIcon newIcon = new ImageIcon("SomePath");
newIcon.getImage().flush();
jLabel1.setIcon(newIcon);

Still having the same problem.. The icon disapears.

What am I doing wrong ?


Update (Full Method) :

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
attempted = myEngine.Attempt('q', word);
if(attempted)
  {
      this.jTextArea1.setText(myEngine.ChangeEncrypt('q', word, this.jTextArea1.getText()));    
  }
  else
  {
      JOptionPane.showMessageDialog(null,"The Letter Q is not in the word", "Error",JOptionPane.WARNING_MESSAGE);
      jButton1.setEnabled(false);
      life ++;
      ImageIcon newIcon = myEngine.UpdatePicture(life);
      newIcon.getImage().flush();
      jLabel1.setIcon(newIcon);
  }

This is the UpdatePicture Method :

public ImageIcon UpdatePicture(int life)
{
  ImageIcon emptyIcon = new ImageIcon();
  if (life == 0)
  {
       ImageIcon iconZero = new ImageIcon("/hang0.gif");
       return iconZero;
  }
  if (life == 1)
  {
      ImageIcon iconOne = new ImageIcon("/hang1.gif");
      return iconOne;
  }
  if (life == 2)
  {
      ImageIcon iconTwo = new ImageIcon("/hang2.gif");
      return iconTwo;
  }
  if (life == 3)
  {
      ImageIcon iconThree = new ImageIcon("/hang3.gif");
      return iconThree;
  }
  if (life == 4)
  {
      ImageIcon iconFour = new ImageIcon("/hang4.gif");
      return iconFour;
  }
  if (life == 5)
  {
      ImageIcon iconFive = new ImageIcon("/hang5.gif");
      return iconFive;
  }
  if (life == 6)
  {
      ImageIcon iconSix = new ImageIcon("/hang6.gif");
      return iconSix;
  }

  return emptyIcon;

}

Not sure the whole code was necessary but still it might help.

The life variable starts at 0.
I checked and in the UpdatePicture it hits the "/hang1.gif"; and returns it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T03:40:04+00:00Added an answer on June 14, 2026 at 3:40 am

    If the file is in your src folder then :

    ImageIcon ii = new ImageIcon(getClass().getResource("/myFile.gif"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seems like a simple problem, but I can't find an answer. With cacheing disabled,
Seems like a simple enough question but I can't seem to find the answer.
Seems like newbie's question, but I just can't find the answer. Can I somehow
Seems like a super simple question but I can't find an answer. I'm grabbing
Seems like a basic question but I can't find this anywhere. Basically I've got
Seems like a basic question but I just can't figure it out: xcode 5.0
Seems like a beginner question but I can't seem to figure it out ...
Seems like I'd be able to find this, but can't turn up anything. Have
Seems like a simple thing but I can't seem to find a way to
Seems like an easy problem, but I am not able to figure it out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.