Solved

JFreeChart. Closing a chart without closing my whole application

Posted on 2006-10-28
16
1,437 Views
Last Modified: 2008-11-16
Hi Experts,

I have developed an application and in my main menu I have a choice to graph data.
I am using JFreeChart library to develop graphs.
Everything is OK. I can get a chart but it is in a separate Chart panel and when I close the ChartPanel it also closes my whole application. What can I do ?

I want to be able to put the graph in my application and be able to close the graph without closinh my application
0
Comment
Question by:blarouche
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
16 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 17825284
You need to

panelDisplayingFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

0
 

Author Comment

by:blarouche
ID: 17825295
CEHJ

Here is part of my code when I create the Chart panel :


final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(800, 400));
setContentPane(chartPanel);


Do I have to include this code ?

chartPanel.setDefaultCloseOperation(ApplicationFrame.DISPOSE_ON_CLOSE);
0
 

Author Comment

by:blarouche
ID: 17825301
This is my class declaration. it extends ApllicationFrame :

public class HighLowChartDemo extends ApplicationFrame {
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 86

Expert Comment

by:CEHJ
ID: 17825303
>>
Do I have to include this code ?

chartPanel.setDefaultCloseOperation(ApplicationFrame.DISPOSE_ON_CLOSE);
>>

Just

Do I have to include this code ?

setDefaultCloseOperation(ApplicationFrame.DISPOSE_ON_CLOSE);

by the looks
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17825306
Sorry, that was meant to be


>>
Do I have to include this code ?

chartPanel.setDefaultCloseOperation(ApplicationFrame.DISPOSE_ON_CLOSE);
>>

Just

setDefaultCloseOperation(ApplicationFrame.DISPOSE_ON_CLOSE);

by the looks
0
 

Author Comment

by:blarouche
ID: 17825323
I have added the code.
I still have the same problem, it closes my whole application
0
 

Author Comment

by:blarouche
ID: 17825337
My Listener is in my main application class but my ChartDemo class where I create my ChartPanel is in another class and package:

class MyChartListener extends AbstractAction{
           
                                     
                     //display message dialog when user selects Comments ...
                        public void actionPerformed( ActionEvent event )
                        {
                              
                        final HighLowChartDemo chrt = new HighLowChartDemo("eurodollars","Eurodollars Daily",quotes);
                      chrt.pack();
                      RefineryUtilities.centerFrameOnScreen(chrt);
                      chrt.setVisible(true);
                      setDefaultCloseOperation(ApplicationFrame.DISPOSE_ON_CLOSE);

                           }
                             
                  }// My ChartListener



      public class HighLowChartDemo extends ApplicationFrame {

      protected String symbol = "";    
      protected Price         price;
      protected String configurationFile = "";      
      
      private double[] high;
      private double[] low;
      private double[] close;
      private double[] open;
      private int[] date;      
      private Date[] d;
      private double[] volume;
      public DBQuotes pointer;

      /**
       * Constructor
       * @param symbol
       */
      public HighLowChartDemo(String Symbol, final String title, DBQuotes point){
      
            super(title);
            this.symbol = Symbol;
            this.pointer = point;
            execute();
 
      }


private void execute(){

      
    /**
     * Loads Daily Prices
     */
    price = getPrices(symbol,pointer);        
    if (price.getSize()==0){
        System.out.println("No quotes founds for symbol "+symbol+", system can't works.");
        System.exit(1);
    }

    high = new double[price.getSize()];
    low  = new double[price.getSize()];
    close = new double[price.getSize()];
    open = new double[price.getSize()];
    date = new int[price.getSize()];    
    volume = new double[price.getSize()];  
    d = new Date[price.getSize()];  
   
   
    for (int i=price.getFirst();i<price.getLast()+1;i++){
                      
          high[i] = price.getHigh(i);
          //System.out.println(price.getHigh(i));
          low[i] = price.getLow(i);
          //System.out.println(price.getLow(i));
          close[i] = price.getClose(i);
          //System.out.println(price.getClose(i));
          open[i] = price.getOpen(i);
          //System.out.println(price.getOpen(i));
          date[i] = price.getDate(i);
 
           try{
                 DateFormat sdf = new SimpleDateFormat("yyyyMMdd");      
                 d[i] = sdf.parse(Integer.toString(price.getDate(i)));
                 }catch (ParseException e) {
                 }
          
                volume[i] = price.getVolume(i);      
     
          }
      
      
   
          final DefaultHighLowDataset dataset = new DefaultHighLowDataset("Chart for "+symbol,d,high,low,open,close,volume);
 
          // code for a candlestick type chart
          final JFreeChart chart = createChart(dataset);
          chart.getXYPlot().setOrientation(PlotOrientation.VERTICAL);
       
          
          /**code for bar chart only
          final JFreeChart chart = ChartFactory.createHighLowChart("High-Low-Open-Close Demo","Time", "Value",dataset, true);
          final DateAxis axis = (DateAxis) chart.getXYPlot().getDomainAxis();
          axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
          
                    
            }





0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 17825346
Try

chrt.setDefaultCloseOperation(ApplicationFrame.DISPOSE_ON_CLOSE);
0
 

Author Comment

by:blarouche
ID: 17825351
Same result
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17825358
OK. Try setting it to

chrt.setDefaultCloseOperation(ApplicationFrame.DO_NOTHING_ON_CLOSE);
0
 

Author Comment

by:blarouche
ID: 17825363
Maybe I should include the ChartDemo class in my my application class and create the ChartPanel inside that class ?
0
 

Author Comment

by:blarouche
ID: 17825376
Same result
0
 

Author Comment

by:blarouche
ID: 17825384
CEHJ

I have to leave for a few hours. I'll be back this afternoon.
I would like to solve this problem as soon as possible.
I'll contact you this afternoon.


Thank you
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17825414
I personally would make the container holding the chart a JDialog, not a JFrame
0
 

Author Comment

by:blarouche
ID: 17825813
I solved my problem in changing extends AplicationFrame by extends Frame in my ChartDemo class


Thank you
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17825855
:-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

691 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