我在做java单机版时,根据数据用jFreeChart 生成了一张图片 并且加载到一个JLabel上,
......
//debtRate,investRate,riskRate 是根据上一界面传来的参数计算出来的值
if(debtRate==0&&investRate==0&&riskRate==0){
label = new JLabel();
}else {
double[][] data = {{debtRate,investRate,riskRate}};
String[] rowKeys = {" "};
String[] cowKeys = {"z","t","f"};
String filepath = null;
filepath = "./FNA/Custom/"+cusDataSchema.getCustomNo()+"/";
File file = new File(filepath+"bar.png");
if(file.exists()){
System.out.println("删除原有图片");
file.delete();
System.out.println("已经删除原有图片");
}
chart.makeBarChart(data, cowKeys, rowKeys, "bar.png", null, null, null, filepath); // 用JFreeChart 生成图片
ImageIcon img = new ImageIcon(filepath+"bar.png");
label = new JLabel(img);
}
......
为什么当我再回到这个界面时,我已经改变了debtRate,investRate,riskRate 的值,并且原有图片已经从文件中删除并且生成了新的图片,但是label加载的还是原来的图片呢??? 是不是从内存中读取的原图片?? 该怎么清除呢?? 怎么样才能在我下次进来时label能加载新的图片??
......
//debtRate,investRate,riskRate 是根据上一界面传来的参数计算出来的值
if(debtRate==0&&investRate==0&&riskRate==0){
label = new JLabel();
}else {
double[][] data = {{debtRate,investRate,riskRate}};
String[] rowKeys = {" "};
String[] cowKeys = {"z","t","f"};
String filepath = null;
filepath = "./FNA/Custom/"+cusDataSchema.getCustomNo()+"/";
File file = new File(filepath+"bar.png");
if(file.exists()){
System.out.println("删除原有图片");
file.delete();
System.out.println("已经删除原有图片");
}
chart.makeBarChart(data, cowKeys, rowKeys, "bar.png", null, null, null, filepath); // 用JFreeChart 生成图片
ImageIcon img = new ImageIcon(filepath+"bar.png");
label = new JLabel(img);
}
......
为什么当我再回到这个界面时,我已经改变了debtRate,investRate,riskRate 的值,并且原有图片已经从文件中删除并且生成了新的图片,但是label加载的还是原来的图片呢??? 是不是从内存中读取的原图片?? 该怎么清除呢?? 怎么样才能在我下次进来时label能加载新的图片??
我试过了 不好使没有用的。
你好,这个问题解决了吗,我也碰到这样的问题