Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-20-2009, 09:09 PM
Member
 
Join Date: Apr 2009
Posts: 7
Rep Power: 0
KeeFy is on a distinguished road
Default [SOLVED] Closing a Panel
Hi, I've got a little bit of a problem here. I've got an application that's calling this class that uses JFreeChart to display a gantt chart. The problem is when i close the gantt chart panel, it closes the the whole app.

Anyone have any clues?

Thanks in advance.

Code:
        final IntervalCategoryDataset dataset = createDataset(Data, thedates, type);
        final JFreeChart chart = createChart(dataset);

        // add the chart to a panel...
        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(640, 480));
        setContentPane(chartPanel);

       final CategoryPlot plot = (CategoryPlot) chart.getPlot();
       Stroke stroke = new BasicStroke();
        plot.setDomainGridlinesVisible(true);
     if(type == 1)
     {     
         for( int g = 0 ; g < Data.length ; g++)
         {   
           plot.addDomainMarker(new CategoryMarker("Batch"+g+"", Color.BLACK, stroke, Color.BLACK, stroke, 0.05f));
         }
     }
       
       if(type == 2)
       {
        {                   
        for( int a= 0 ; a< Data.length; a++)
        {   
           
            
            for (int b = 0; b < Data[a].length ; b++ )
                
            {
                
                if (Data[a][b][0] == null)
                {
                    b = Data[a].length;
                }
                else{
                    plot.addDomainMarker(new CategoryMarker(Data[a][b][4], Color.BLACK, stroke, Color.BLACK, stroke, 0.01f));
                }
            }

        }
      } 
       }
    if (type == 3)
    {
      {                   for( int a= 0 ; a< Data.length; a++)
        {  
           
            
            for (int b = 0; b < Data[a].length ; b++ )
                
            {
                

                if (Data[a][b][0] == null)
                {
                    b = Data[a].length;
                }
                else{
                    plot.addDomainMarker(new CategoryMarker(Data[a][b][0], Color.BLACK, stroke, Color.BLACK, stroke, 0.01f));
                }
            }

        }
      } 
    }
    
    }
  
    


    
 public static IntervalCategoryDataset createDataset(String Data[][][], String thedates, int type) {

     final TaskSeriesCollection collection = new TaskSeriesCollection();
     Calendar abcd = Calendar.getInstance();
     int typeofchart = type;
     String datestrip[] = thedates.split(",");

        int yy = Integer.parseInt(datestrip[0]);
        int mm = Integer.parseInt(datestrip[1]);
        int dd = Integer.parseInt(datestrip[2]);
       abcd.set(Calendar.YEAR, yy);
       abcd.set(Calendar.MONTH, mm);
       abcd.set(Calendar.DATE, dd);

 if (typeofchart == 1)
 {
        for( int x = 0 ; x < 4; x++)
        {   
            String tst = "error";
            if(x == 0)
            {
                tst = "Crusher";
            }
            else if (x == 1)
            {
                tst = "Press";
            }
            else if (x == 2)
            {
                tst = "Fermenter 1";
            }
            else
            {
                tst = "Fermenter 2";
            }
            
            final TaskSeries cAdd = new TaskSeries( tst );
            
     
                
            {
               for (int a = 0;  a < Data.length; a ++)
               {

                if (Data[a][x][0] == null)
                {
                    break;

                }
                else
                {
                String dA = Data[a][x][2];
                String dB = Data[a][x][3];

                long dataA = Long.parseLong(dA.trim());
                long dataB = Long.parseLong(dB.trim());
                dataA = dataA*60000;
                dataB = dataB*60000;
                dataA = dataA + abcd.getTimeInMillis();
                dataB = dataB + abcd.getTimeInMillis();
    
                
                cAdd.add(new Task("Batch" + a, new SimpleTimePeriod(dataA,dataB)));
 
                }
            }
            }
        collection.add(cAdd);
        }
 }
        else if (typeofchart == 2)
        {
            
                   for( int a= 0 ; a< Data.length; a++)
        {  
            final TaskSeries cAdd = new TaskSeries("Batch "+ a);
            
            for (int b = 0; b < Data[a].length ; b++ )
                
            {

                if (Data[a][b][0] == null)
                {
                    b = Data[a].length;
                }
                else
                {
                String dA = Data[a][b][2];
                String dB = Data[a][b][3];

                long dataA = Long.parseLong(dA.trim());
                long dataB = Long.parseLong(dB.trim());
                dataA = dataA*60000;
                dataB = dataB*60000;
                dataA = dataA + abcd.getTimeInMillis();
                dataB = dataB + abcd.getTimeInMillis();
   
                
                cAdd.add(new Task(Data[a][b][4], new SimpleTimePeriod(dataA,dataB)));
                
                }
            }
        collection.add(cAdd);
        } 
        }
        else
        {
            
                   for( int a= 0 ; a< Data.length; a++)
        {   
            final TaskSeries cAdd = new TaskSeries("Batch "+ a);
            
            for (int b = 0; b < Data[a].length ; b++ )
                
            {

                if (Data[a][b][0] == null)
                {
                    b = Data[a].length;
                }
                else
                {
                String dA = Data[a][b][2];
                String dB = Data[a][b][3];
                long dataA = Long.parseLong(dA.trim());
                long dataB = Long.parseLong(dB.trim());
                dataA = dataA*60000;
                dataB = dataB*60000;
                dataA = dataA + abcd.getTimeInMillis();
                dataB = dataB + abcd.getTimeInMillis();
                
                
                cAdd.add(new Task(Data[a][b][0], new SimpleTimePeriod(dataA,dataB)));
               
               
                }
            }

        collection.add(cAdd);
        } 
        }
   return collection;
    }

    

    private JFreeChart createChart(final IntervalCategoryDataset dataset) {
        final JFreeChart chart = ChartFactory.createGanttChart(
            "Winery Time Frame",  // chart title
            "Task",              // domain axis label
            "Date",              // range axis label
            dataset,             // data
            true,                // include legend
            true,                // tooltips
            false                // urls
        );    
        return chart;    
    }
    


    
    //@SuppressWarnings("static-access")
    public static void DisplayChart(File sourcef, String thedates, int type)
    {
        String[][][] Buffer = new String[1][1][1];
        final gantt output = new gantt("Gantt Chart", Buffer, sourcef, thedates, type);
        output.pack();
        RefineryUtilities.centerFrameOnScreen(output);
        output.setVisible(true);

    }
}
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 05-20-2009, 09:32 PM
Member
 
Join Date: Jan 2009
Posts: 2
Rep Power: 0
yemmynik1 is on a distinguished road
Default backing up my database from jsp
Moderator: hijack post deleted.

Last edited by Fubarable; 05-21-2009 at 12:25 AM.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-21-2009, 12:30 AM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 5,968
Rep Power: 7
Fubarable is on a distinguished road
Default
Quote:
Hi, I've got a little bit of a problem here. I've got an application that's calling this class that uses JFreeChart to display a gantt chart. The problem is when i close the gantt chart panel, it closes the the whole app.
KeeFy,
Much of your posted code appears to be unrelated to the problem at hand, and the key code that's causing the problem may not have been posted. Question: are you displaying the chart in its own free-standing window? If so, are you using a JFrame? If so, change this to a JDialog. If this doesn't solve the problem, then you're going to have to do some debugging to try to create the smallest compilable program that will reproduce your problem. If doing this doesn't help you find the solution, then you can post this smaller more reasonable code here and we can have a look at it.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-21-2009, 12:57 AM
Member
 
Join Date: Apr 2009
Posts: 7
Rep Power: 0
KeeFy is on a distinguished road
Default
,,,,,,,,,,

Last edited by KeeFy; 05-21-2009 at 03:07 AM.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-21-2009, 01:06 AM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 5,968
Rep Power: 7
Fubarable is on a distinguished road
Default
I didn't want the entire code. Please take another look at my post. You may wish to answer the questions that I posted regarding JFrame. Thanks.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-21-2009, 01:25 AM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 5,968
Rep Power: 7
Fubarable is on a distinguished road
Default
OK, I've gone through all of your code (whew!) and answered the question myself: yes you use use a JFrame, "Test" to display what should be a JDialog. Change this, use a JDialog instead and I'll bet your problem is solved.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 05-21-2009, 02:26 AM
Member
 
Join Date: Apr 2009
Posts: 7
Rep Power: 0
KeeFy is on a distinguished road
Default
Thanks! I realised i was extending the application frame instead of creating a new one! All i did was create it's own JFrame, and violla!

Thanks for the help!
Cheers.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 05-21-2009, 04:14 AM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 5,968
Rep Power: 7
Fubarable is on a distinguished road
Default
Glad you have it working, but still if "Test" is a JFrame, I'd use a JDialog instead. Also, I wouldn't extend JAnything here but instead would create a standard JDialog and add my stuff to a JPanel and then add that JPanel to the dialog's contentPane. Best of luck.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Closing an Editor janpol1 Eclipse 0 02-14-2009 05:00 PM
Prevent escape from closing a SWT dialog Java Tip SWT 0 07-02-2008 08:58 PM
Can i use a resultset more than once without closing it haneeshrawther Database 5 06-26-2008 04:16 AM
JFrame (closing under a condition) Java Tip Java Tips 0 03-12-2008 12:17 PM
Closing packages uncopywritable New To Java 0 08-14-2007 12:47 AM


All times are GMT +2. The time now is 06:43 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org