Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/03/2014, 20:17
AGmzT
 
Fecha de Ingreso: febrero-2014
Mensajes: 16
Antigüedad: 10 años, 2 meses
Puntos: 0
Invocar JComboBox

Hola gente,

Necesito ayuda;

En un JFrame tengo 6 ComboBox que están anidados en pares (lo que ocurre en el primero afecta al segundo) lo que me genera mucho codigo.

En su lugar quiero que el JFrame invoque 3 JPanel que tengan un par de ComboBox cada uno, ahora bien en el JPanel tengo un metodo actionPerformed con un parametro actionEvent, que es lo que me trae problemas al invocar el método ya que no tengo idea de como se instancia ni nada.

Pueden darme una mano??

Aca les dejo el código

La clase del JPanel:

package Interface;

import java.awt.Font;

public class ComboPanel extends JPanel {

/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Create the panel.
*/
@SuppressWarnings("rawtypes")
private JComboBox B;
private JLabel lblB;
@SuppressWarnings("rawtypes")
private JComboBox V;
private JLabel lblV;
private JPanel contentPane;
@SuppressWarnings("unused")
private String[] listaCol;
private Dbs db;

@SuppressWarnings({ "unchecked", "rawtypes" })
public ComboPanel(String[] listaCol) {
super();
this.listaCol = listaCol;
contentPane= new JPanel();
contentPane.setLayout(null);

lblB = new JLabel("Seleccione parametro");
lblB.setFont(new Font("SansSerif", Font.BOLD, 18));
lblB.setBounds(10, 10, 200, 30);
contentPane.add(lblB);

B = new JComboBox(listaCol);
B.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try{
do_B_actionPerformed(arg0);
}catch (PersExcep e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});

B.setFont(new Font("SansSerif", Font.PLAIN, 18));
B.setToolTipText("Busque por");
B.setBounds(10, 40, 250, 30);
contentPane.add(B);

lblV = new JLabel("Seleccione valor");
lblV.setFont(new Font("SansSerif", Font.BOLD, 18));
lblV.setBounds(10, 70, 200, 30);
contentPane.add(lblV);

V = new JComboBox();
V.setToolTipText("Busque por");
V.setFont(new Font("SansSerif", Font.PLAIN, 18));
V.setBounds(10, 100, 250, 30);
contentPane.add(V);

}

@SuppressWarnings({"unchecked" })
public void do_B_actionPerformed(ActionEvent arg0) throws PersExcep{

try{

V.removeAllItems();
String aja =(String)B.getSelectedItem();
db.obtenerVal(aja);
if(B.getSelectedItem()=="Codigo SAP"||B.getSelectedItem()=="Codigo de Barras" ||B.getSelectedItem()=="Codigo Cliente" ){
V.setEditable(true);
lblV.setText("Escriba el "+B.getSelectedItem() );
}else if(B.getSelectedItem()=="Presentacion"){
for(int i =0;i< db.getILsize();i++ ){
V.addItem(db.getILista(i));
}
}else{
for(int i =0;i< db.getSLsize();i++ ){
V.addItem(db.getSLista(i));
}
}

}catch (Exception ex){
ex.printStackTrace();
throw new PersExcep();

}
}


}

y el método en la clase del JFrame donde trato de invocar un nuevo JPanel

cp = new ComboPanel(listaCol);
contentPane.add(cp);
cp.do_B_actionPerformed(ActionEvent arg0);