?
Solved

How do I update a jPanel wth a Jfreechart

Posted on 2009-02-22
1
Medium Priority
?
5,901 Views
Last Modified: 2013-12-14
I'm trying to create a data file viewer with an application I'm writing. It works the first time, but if you try to press the button again and change the source file and view another data file, it processes it but does not change the graph. Suggestions?
private void jButtonSelectFileActionPerformed(java.awt.event.ActionEvent evt) {                                                  
        // TODO add your handling code here:
        if (txtChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            File f = txtChooser.getSelectedFile();
            configSettings.setDataFile(f.getName());
            jTextFieldODFDataFileLocation.setText(f.getAbsolutePath());
            dataStoragePath = f.getParent();
            configSettings.setDataStoragePath(dataStoragePath);
            final XYDataset dataset = createDataset(configSettings.getDataStoragePath()
                    +"\\"+configSettings.getDataFile());
            final JFreeChart chart = createChart(dataset);
            ChartPanel panel = new ChartPanel(chart);
            panel.setSize(jPanelChart.getWidth(),jPanelChart.getHeight());
            panel.setVisible(true);
            jPanelChart.add(panel);
            jPanelChart.validate();
            jPanelChart.repaint();
        }
    }

Open in new window

0
Comment
Question by:PmiDeveloper
1 Comment
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 23706988
u need to first remove the old one, and call revalidate()

            jPanelChart.removeAll();
            jPanelChart.add(panel);
            jPanelChart.revalidate();

0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question