I'm about to make selection menus consist of 3 JComboboxes, and they are related to prior choice.
When I choose first menu, I need to update next JCombobox by requesting JSON, and so on for last menu.
What I tried : put addActionListener to update next JCombobox, but it seems not working.
It's hard to find problem as I cannot catch it through debugger.
The method 'getParsedData' returns JSONArray came from JSON file.
JPanel test = new JPanel();
test.setLayout(new FlowLayout());
add(test);
top = rc.getParsedData("top");
ArrayList<String> topList = rc.getLocationList(top);
location1 = new JComboBox(topList.toArray(new String[topList.size()]));
location1.addActionListener(e -> {
try {
rc.setCode(top, location1.getSelectedItem().toString());
mdl = rc.getParsedData("mdl");
ArrayList<String> mdlList = rc.getLocationList(mdl);
location2 = new JComboBox(mdlList.toArray(new String[mdlList.size()]));
} catch (IOException | ParseException ioException) {
ioException.printStackTrace();
}
});
test.add(location1);
location2.addActionListener(e -> {
try {
leaf = rc.getParsedData("leaf");
rc.setCode(mdl, location2.getSelectedItem().toString());
ArrayList<String> leafList = rc.getLocationList(leaf);
location3 = new JComboBox(leafList.toArray(new String[leafList.size()]));
rc.setXY(leaf, location3.getSelectedItem().toString());
} catch (IOException | ParseException ioException) {
ioException.printStackTrace();
}
});
test.add(location2);
test.add(location3);