i am making a medical drug software program and i want the user to be able to select a sickness category (respiratory disease, cardiovascular disease etc) from a jcombo box that is populated by the category array.
Once this category is selected i want another jcombobox to be populated only with drugs relevant to that category.
The problem i am having is that i cant seem to get the values of whats in the jcombobox and use those in an If statement to then populate or make visible the second box with the relevant drugs.
public CatergoryBar(ArrayList<Catergory> category)
{
new GridBagLayout();
Dimension dim = getPreferredSize();
dim.width = 250;
setPreferredSize(dim);
setBorder(BorderFactory.createEtchedBorder());
c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.weightx = 1;
c.weighty = 1;
c.fill = GridBagConstraints.NONE;
categoryBox = new JComboBox(category.toArray());
add(categoryBox, c);
c.gridy++;
categoryBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
String item = String.valueOf(categoryBox.getSelectedItem());
if(item.equals("Respiratory Disease"))
{
respBox = new JComboBox(PFormulary.respDiseases.toArray());
add(respBox, c);
c.gridy++;
}
}
});{
My respiratory combobox gets displayed if i do it normally outside of the item listener but as soon as i put it inside of the item listener nothing pops up when i click on "Respiratory Disease".
Thanks in advance!