Results 1 to 8 of 8
  1. #1
    KeeFy is offline Member
    Join Date
    Apr 2009
    Posts
    7
    Rep Power
    0

    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. :)

    Java 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);
    
        }
    }

  2. #2
    yemmynik1 is offline Member
    Join Date
    Jan 2009
    Posts
    2
    Rep Power
    0

    Default backing up my database from jsp

    Moderator: hijack post deleted.
    Last edited by Fubarable; 05-20-2009 at 11:25 PM.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    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.

  4. #4
    KeeFy is offline Member
    Join Date
    Apr 2009
    Posts
    7
    Rep Power
    0

    Default

    ,,,,,,,,,,
    Last edited by KeeFy; 05-21-2009 at 02:07 AM.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    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.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    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.

  7. #7
    KeeFy is offline Member
    Join Date
    Apr 2009
    Posts
    7
    Rep Power
    0

    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.

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    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.

Similar Threads

  1. Closing an Editor
    By janpol1 in forum Eclipse
    Replies: 0
    Last Post: 02-14-2009, 04:00 PM
  2. Prevent escape from closing a SWT dialog
    By Java Tip in forum SWT
    Replies: 0
    Last Post: 07-02-2008, 07:58 PM
  3. Replies: 5
    Last Post: 06-26-2008, 03:16 AM
  4. JFrame (closing under a condition)
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-12-2008, 11:17 AM
  5. Closing packages
    By uncopywritable in forum New To Java
    Replies: 0
    Last Post: 08-13-2007, 11:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •