
05-20-2009, 09:09 PM
|
|
Member
|
|
Join Date: Apr 2009
Posts: 7
Rep Power: 0
|
|
[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);
}
} |
|
|

05-20-2009, 09:32 PM
|
|
Member
|
|
Join Date: Jan 2009
Posts: 2
Rep Power: 0
|
|
backing up my database from jsp
Moderator: hijack post deleted.
Last edited by Fubarable; 05-21-2009 at 12:25 AM.
|
|

05-21-2009, 12:30 AM
|
 |
Moderator
|
|
Join Date: Jun 2008
Posts: 5,968
Rep Power: 7
|
|
|
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.
|
|

05-21-2009, 12:57 AM
|
|
Member
|
|
Join Date: Apr 2009
Posts: 7
Rep Power: 0
|
|
|
,,,,,,,,,,
Last edited by KeeFy; 05-21-2009 at 03:07 AM.
|
|

05-21-2009, 01:06 AM
|
 |
Moderator
|
|
Join Date: Jun 2008
Posts: 5,968
Rep Power: 7
|
|
|
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.
|
|

05-21-2009, 01:25 AM
|
 |
Moderator
|
|
Join Date: Jun 2008
Posts: 5,968
Rep Power: 7
|
|
|
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.
|
|

05-21-2009, 02:26 AM
|
|
Member
|
|
Join Date: Apr 2009
Posts: 7
Rep Power: 0
|
|
|
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.
|
|

05-21-2009, 04:14 AM
|
 |
Moderator
|
|
Join Date: Jun 2008
Posts: 5,968
Rep Power: 7
|
|
|
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.
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT +2. The time now is 06:43 PM.
|
|