como cambiar la imagen de un JLabel en netbeans

Tagged:  

hola, tengo el siguiente problema en netbeans puedo cargar imagenes en dos jpanel guardando las imagenes en dos Jlabel y cuando cargo las imagenes por primera vez todo funciona perfectamente y puedo ver las imagenes, pero si requiero cambiarlas los nuevos archivos se cargan peor las imagenes no cambian. como actualizarlas??
aqui esta mi codigo:

clase principal
segmento de codigo

Graficas Graficar=new Graficas();
Graficar.Graf_Frec_acum(arreglo_util,alto,ancho);
j=new JLabel();
Graficar.Carga_grafica(j);
j.setBounds(0, 0, ancho, alto);
CONTENEDORGRAFICA.add(j); /// jpanel 1
//j.repaint();

////////////////////////////////////////////////////////
Graficar.Graf_Dist_tam(Disttam,alto1,ancho1,arreglo_util);
d=new JLabel();
Graficar.Carga_grafica(d);
d.setBounds(0, 0, ancho1, alto1);
CONTENEDORGRAFICA1.add(d); //// jpanel 2
//d.repaint();
}

clase GRAFICAS
********************************************************************************************************************
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package carga.de.archivos;

import java.awt.Image;
import java.awt.image.BufferedImage;
import javax.swing.*;
import javax.swing.JLabel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

/**
*
* @author Cparticulas1
*/
public class Graficas
{
private BufferedImage imagen1;

/**
* The starting point for the demo.
*
* @param args ignored.
*/
public void Image Graf_Frec_acum(String [] datos, int ancho, int alto)
{
//System.out.println(datos.length);
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for(int i=0;i<(datos.length/2);i++)
{
dataset.setValue(Double.parseDouble(datos[i+(datos.length/2)])," ",datos[i]);
//dataset.setValue(Double.parseDouble(distTam[i]),datos[i],"catin1 ");
}
JFreeChart cuadro = ChartFactory.createLineChart("Frecuencia Acumulada","tamaño de Parcitula en micras","x 100",dataset,PlotOrientation.VERTICAL,false,true,true);
CategoryPlot ploteo=(CategoryPlot)cuadro.getPlot();
CategoryAxis ejeX=(CategoryAxis)ploteo.getDomainAxis();
ejeX.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
imagen1=cuadro.createBufferedImage(alto,ancho);

}
public void Graf_Dist_tam(String[] distTam,int ancho, int alto, String[] datos)
{
//System.out.println(distTam.length);
DefaultCategoryDataset dataset0= new DefaultCategoryDataset();
for(int i=0;i<(distTam.length);i++)
{
dataset0.setValue(Double.parseDouble(distTam[i])," ",datos[i]);
//dataset.setValue(Double.parseDouble(distTam[i]),datos[i],"catin1 ");
}
JFreeChart cuadro = ChartFactory.createBarChart("Distribución de Tamaños","tamaño de Parcitula en micras","x 100",dataset0,PlotOrientation.VERTICAL,false,true,true);
CategoryPlot ploteo=(CategoryPlot)cuadro.getPlot();
CategoryAxis ejeX=(CategoryAxis)ploteo.getDomainAxis();
ejeX.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
imagen1=cuadro.createBufferedImage(alto,ancho);

}

public void Carga_grafica (JLabel etiqueta)
{
ImageIcon jues=new ImageIcon(imagen1);
etiqueta.setIcon(jues);
etiqueta.repaint();
}

Enviar un comentario nuevo

El contenido de este campo se mantiene privado y no se mostrará públicamente.
  • Las direcciones de las páginas web y las de correo se convierten en enlaces automáticamente.
  • Etiquetas HTML permitidas: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Saltos automáticos de líneas y de párrafos.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <pre>. The supported tag styles are: <foo>, [foo].

Más información sobre opciones de formato