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 8608369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:35:41+00:00 2026-06-12T03:35:41+00:00

So basically im creating a GUI that allows the user to select a file,

  • 0

So basically im creating a GUI that allows the user to select a file, this file is check to be a .wav file. Then this file’s data is graphed through JFreechart.
This graph or image created by Jfreechart i want to put into the JFrame.
The problem is that the code:

 ImageIcon myIcon1 = new ImageIcon("blah.jpg");   
 JLabel graphLabel1 = new JLabel(myIcon1);
 southContent.add(graphLabel1);

must be created & declared in the method where i create the JFrame ( must be added to the frame )
thus i cannot dynamically update the image to new created graphs, depending on what file the user selects. ( on selection of a new file, via button a new graph image is created )

is there a way to force

  ImageIcon myIcon1 = new ImageIcon("blah.jpg");   
  JLabel graphLabel1 = new JLabel(myIcon1);
  southContent.add(graphLabel1);

to update to the new image ( in the same direcotry, with the same name )

or is there a way using Mapping to set the image name (“blah.jpg”) dynamically with a counter?

here is my SSCCE

public class gui extends JFrame {

    ImageIcon myIcon1 = new ImageIcon("C:/location/chart1.jpg");
    JLabel graphLabel1 = new JLabel(myIcon1);

    gui() {
        // create Pane + contents & listeners...
        JPanel content = new JPanel();
        JPanel southContent = new JPanel();
        content.setLayout(new FlowLayout());
        content.add(open_File);
        // Jfreechart graph image  -- not visible until selected
        graphLabel1.setVisible(false);
        // this is the graph image being added to the panel
        southContent.add(graphLabel1);
        southContent.setLayout(new FlowLayout());
        // add action listeners to buttons
        open_File.addActionListener(new OpenAction());
        // set Pane allignments & size...
        this.setContentPane(content);
        this.add(southContent, BorderLayout.SOUTH);
        this.setTitle("Count Words");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setSize(1100, 720);
        this.setLocationRelativeTo(null);
    }

    //  opening selected file directory.
    class OpenAction implements ActionListener {

        public void actionPerformed(ActionEvent ae) {
            /// gets user selection ( file ) and procesess .wav data into array
            /// loops through array creating X series for JfreeChart
            // Add the series "series" to data set "dataset"
            dataset.addSeries(series);
            // create the graph
            JFreeChart chart = ChartFactory.createXYLineChart(
                    ".Wav files", // Graph Title
                    "Bytes", // X axis name
                    "Frequency", // Y axis name
                    dataset, // Dataset
                    PlotOrientation.VERTICAL, // Plot orientation
                    true, // Show Legend
                    true, // tooltips
                    false // generate URLs?
                    );
            try {
                ChartUtilities.saveChartAsJPEG(
                        new File("C:/location/chart1.jpg"), chart, 1000, 600);
            } catch (IOException e) {
                System.err.println("Error occured:  " + e + "");
            }
            // !!!!! this is where i need to set the ImageIcon added to the 
            //  panel in "gui" to this new created Graph image ("chart1.jpg") 
            //  as above
            //  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            // sets the image label itself to visible as a new image has been
            // added ot it
            graphLabel1.setVisible(true);
        }
    }
}
  • 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-12T03:35:42+00:00Added an answer on June 12, 2026 at 3:35 am

    Just add the JLabel to its container as you usually do. Then, once you created the image and you have an instance of an ImageIcon, just call the setIcon() method for the JLabel.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So i have been creating this framework thing that basically puts together source code
I am basically creating an iphone app that get's it's data from wordpress. Wordpress
Basically creating a file manager. User clicks browse and a div populates with folders
I just need help. Basically I am creating a windows appllication that sends bulk
Basically I have a tabbed Panel I'm creating. When the user click on a
Basically, I am creating an XML file by taking the values from a column
I am creating an application that basically places a drawable into an imageView onClick.
I am creating a 3 tier application. Basically it goes Client -> (through optional
I am basically creating an API in php, and one of the parameters that
I am basically creating a xlsx file but I am getting an error while

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.