I want to create a GUI in which the combo-box allows me to open a new JFrame by pressing an item from the combo-box. Any ideas on how could I dot that?
            Asked
            
        
        
            Active
            
        
            Viewed 4,987 times
        
    3 Answers
4
            Instead of that, how about you use an appropriate layout manager (e.g. CardLayout)? This will enable you to easily toggle views within the same container.
 
    
    
        mre
        
- 43,520
- 33
- 120
- 170
- 
                    2I have never used CardLayout until now. I'll see what I can do. – Radu Stejerean Mar 30 '12 at 13:17
- 
                    2For another example, see [this answer](http://stackoverflow.com/a/5786005/418556). See also [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/questions/9554636/the-use-of-multiple-jframes-good-bad-practice/9554657#9554657) for links to two answers with many other alternatives suited to different use-cases. – Andrew Thompson Mar 30 '12 at 14:00
2
            
            
        Add an ActionListener to the JComboBox:
JComboBox combo = new ...
combo.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
    // This code runs when an item is selected in the combo.
    JFrame frm = new ...
    frm.setVisible(true);
  }
});
 
    
    
        Adamski
        
- 54,009
- 15
- 113
- 152
1
            
            
        Add an event listener to the comboBox and just handle the event to generate a new JFrame
 
    
    
        GLlompart
        
- 261
- 5
- 18
