Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1541
  • Last Modified:

JFreeChart. Closing a chart without closing my whole application

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
blarouche
Asked:
blarouche
  • 9
  • 7
1 Solution
 
CEHJCommented:
You need to

panelDisplayingFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

0
 
blaroucheAuthor Commented:
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
 
blaroucheAuthor Commented:
This is my class declaration. it extends ApllicationFrame :

public class HighLowChartDemo extends ApplicationFrame {
0
Technology Partners: 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!

 
CEHJCommented:
>>
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
 
CEHJCommented:
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
 
blaroucheAuthor Commented:
I have added the code.
I still have the same problem, it closes my whole application
0
 
blaroucheAuthor Commented:
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
 
CEHJCommented:
Try

chrt.setDefaultCloseOperation(ApplicationFrame.DISPOSE_ON_CLOSE);
0
 
blaroucheAuthor Commented:
Same result
0
 
CEHJCommented:
OK. Try setting it to

chrt.setDefaultCloseOperation(ApplicationFrame.DO_NOTHING_ON_CLOSE);
0
 
blaroucheAuthor Commented:
Maybe I should include the ChartDemo class in my my application class and create the ChartPanel inside that class ?
0
 
blaroucheAuthor Commented:
Same result
0
 
blaroucheAuthor Commented:
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
 
CEHJCommented:
I personally would make the container holding the chart a JDialog, not a JFrame
0
 
blaroucheAuthor Commented:
I solved my problem in changing extends AplicationFrame by extends Frame in my ChartDemo class


Thank you
0
 
CEHJCommented:
:-)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 9
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now