Solved

JFreeChart. Closing a chart without closing my whole application

Posted on 2006-10-28
16
1,347 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
  • 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
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 
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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
V.simple question about Android packages and libraries 1 22
How to get all the API from website? 11 92
Arrays.asList  VS  ArrayList 4 60
egit plugin on eclipse 8 64
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

831 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