add component to JPanel
Hello everyone,
I have a JComboBox, and when i select an Option i would like to add a new component to the JPanel (just below the JComboBox). This is what i have at the moment, but i must be doing something wrong because it does nothing.
String[] choices ={"Choose option","Option 1","Option 2","Option 3","Option 4","Option 5"};
mainPanelComponent5 =new JComboBox(choices );
mainPanelComponent5.setBounds(100, 70, 150, 20);
mainPanelComponent5.addItemListener(new ItemListener(){
publicvoid itemStateChanged(ItemEvent e){
if (e.getStateChange() == ItemEvent.SELECTED){
JLabel compId =new JLabel("TEST");
compId.setBounds(210, 70, 250, 20);
mainPanel.add(compId);
}
}
});
Any help? thanks in advance

