Hi I have a project to show some information, what I do is to put the specific information in some JPanel. This is a production project and I have 7 production lines, so for each line I use a panelCel and in that panelCel I create the JPanels with the orders, but I don't know why it doesn't show all the orders. I use a thread for each line to fill all the orders so in total I have 7 threads and works fine, but it doesn't actualize when my code finish until I move the mouse or press a button, why its happening this and how can I solve it? I have used the validate() and repaint() methods but it doesn't make a difference.
Here is an example of how I call my threads:
public void actualizarLineas(){
lineaProduccion linea1 = new lineaProduccion(panelCel1, ordenes1);
lineaProduccion linea2 = new lineaProduccion(panelCel2, ordenes2);
lineaProduccion linea3 = new lineaProduccion(panelCel3, ordenes3);
lineaProduccion linea4 = new lineaProduccion(panelCel4, ordenes4);
lineaProduccion linea5 = new lineaProduccion(panelCel5, ordenes5);
lineaProduccion linea6 = new lineaProduccion(panelCel6, ordenes6);
lineaProduccion linea7 = new lineaProduccion(panelCel7, ordenes7);
linea1.start();
linea2.start();
linea3.start();
linea4.start();
linea5.start();
linea6.start();
linea7.start();}
ordenesX are the arrays that have the orders, and this is the class:
public class lineaProduccion extends Thread {
JPanel jpCelula;
String []datos;
public lineaProduccion(JPanel jpCelula, String[] datos) {
this.jpCelula = jpCelula;
this.datos = datos;
}
public JPanel getJpCelula() {
return jpCelula;
}
public void setJpCelula(JPanel jpCelula) {
this.jpCelula = jpCelula;
}
public String[] getDatos() {
return datos;
}
public void setDatos(String[] datos) {
this.datos = datos;
}
@Override
public void run(){
String auxOrdenAct = "0";
String auxOrdenAnt = "0";
String celulaAnterior = "0";
String celulaActual = "0";
Color colorActual = null;
Color colorAnterior = null;
if(datos.length > 0){
int posicionX = 10;
for (String ordenActual : datos) {
final JPanel orden = new JPanel();
orden.setName(ordenActual);
orden.setLocation(posicionX ,15);
orden.setSize(65, 75);
orden.setToolTipText(ordenActual);
auxOrdenAnt = auxOrdenAct;
auxOrdenAct = ordenActual;
if(auxOrdenAnt.equals("0"))
auxOrdenAnt = ordenActual;
celulaAnterior = celulaActual;
celulaActual = jpCelula.getName();
if(!celulaAnterior.equals(celulaActual))
celulaAnterior = celulaActual;
String inf1 = transaccion.obtieneinf1(ordenActual);
if(inf1.equals("-1"))
orden.setBackground(new java.awt.Color(0, 102,153));
final JLabel etiqueta[] = new JLabel[3];
for(int j=0; j<3; j++){
etiqueta[j]= new JLabel("etiqueta" +j);
etiqueta[j].setForeground(Color.white);
}
final String inf2 = transaccion.obtieneinf2(ordenActual);
final String inf3 = transaccion.obtieneinf3(ordenActual);
etiqueta[0].setText(ordenActual);
etiqueta[1].setText(" "+ inf2 + " ");
if(!inf3.equals("-1"))
etiqueta[2].setText(inf3);
orden.add(etiqueta[0]);
orden.add(etiqueta[1]);
orden.add(etiqueta[2]);
posicionX = posicionX + 70;
jpCelula.add(orden);
Dimension d = new Dimension(posicionX , 70);
jpCelula.setPreferredSize(d);
}
} else {
System.out.println("No hay órdenes para esta línea");
}
}}
Basically what I do is to put the information in one JPanel and add it to my jPanel.