Problemas con JComboBox

arcadelak
16 de Octubre del 2003
El codigo es el sigiente:

// ***Este programa funciona para inscribir materias por medio de unas opciones
import java.awt.*;
import javax.swing.*;

public class InscripcionMaterias extends JApplet {

private JButton enviar;


public void init() {
String[] petStrings = {
"Materias",
"Matematicas II",
"Mecanica",
"POO",
"Estadistica",
"Seminario",
"Ingles",
"Catedra"
};

String[] petStrings2 = {
"Grupos",
"Grupo 1",
"Grupo 2",
"Grupo 3",
"Grupo 4"
};


String[] petStrings3 = {
"Materias",
"Matematicas II",
"Mecanica",
"POO",
"Estadistica",
"Seminario",
"Ingles",
"Catedra"
};

String[] petStrings4 = {
"Grupos",
"Grupo 1",
"Grupo 2",
"Grupo 3",
"Grupo 4"
};

//====================================================================================================//

// Create the combo box, select the pig

JComboBox petList = new JComboBox(petStrings);
petList.setSelectedIndex(0);
//petList.Materia6.setVisible(false);


JComboBox petList2 = new JComboBox(petStrings2);
petList2.setSelectedIndex(0);


JComboBox petList3 = new JComboBox(petStrings3);
petList3.setSelectedIndex(0);


JComboBox petList4 = new JComboBox(petStrings4);
petList4.setSelectedIndex(0);

//====================================================================================================//

// Layout

getContentPane().setLayout(new GridLayout(0,2,20,20));
getContentPane().add(petList);
getContentPane().add(petList2);
getContentPane().add(petList3);
getContentPane().add(petList4);
getContentPane().add(enviar=new JButton("Enviar"));


//====================================================================================================//

}
}

y lo que pasa es que no se que hacer para que cuando ejecute el applet y escoja en el primer JComboBox
de materias por ejemplo "POO" en el segundo JComboBox tambien de materias no aparesca la opcion POO;

Mario Lavarreda
16 de Octubre del 2003
//Bueno podrias hacerlo asi

Tienes que tener un panel donde estas poniendo los
JComboBox y darle asi...
si no dale un getContentPane() al APPLET y dale cada vez que borres una opcion lo siguiente

public void deleteOptions(String opcion){
Container c=JFrame.getContentPane();
for(int i=0;i<c.getComponentCoun();i++){
if(c.getComponent(i) instance JComboBox){
JComboBox combo=(JComboBox)c.getComponent(i);
combo.removeItem(opcion);
}

}

}
//Este metodo te removera el String de todos los JComboBox que este en tu panel del Applet

Mario Lavarreda
16 de Octubre del 2003
Perdon no era JFrame era JApplet
Tienes que tener un panel donde estas poniendo los
JComboBox y darle asi...
si no dale un getContentPane() al JAPPLET y dale cada vez que borres una opcion lo siguiente

public void deleteOptions(String opcion){
Container c=JApplet.getContentPane();
for(int i=0;i<c.getComponentCoun();i++){
if(c.getComponent(i) instance JComboBox){
JComboBox combo=(JComboBox)c.getComponent(i);
combo.removeItem(opcion);
}

}