TechArena Community

TechArena Community (http://forums.techarena.in/)
-   Software Development (http://forums.techarena.in/software-development/)
-   -   Close Combo Box in java (http://forums.techarena.in/software-development/1274554.htm)

cyber-noob 24-11-2009 02:31 PM

Close Combo Box in java
 
Hi
Now I have a hands on experience of java. I have a problem in my java problem. I need to know how to close the ComboBox after the project is been selected. It opens the class openo that is perfect but the combobox is open in the new frame. I have posted my code below. Just go through it.
Code:

public opencb() {
    String[] proname = { "2004", "2003", "2005" };
    JComboBox pro = new JComboBox(proname);
    pro.setSelectedIndex(2);
    pro.addActionListener(this);
    add(pro, BorderLayout.PAGE_START);
    setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
}
public void actionPerformed(ActionEvent e) {
      JComboBox cb = (JComboBox)e.getSource();
      String proname = (String)cb.getSelectedItem();
      if (proname.equals("2004")) {
        openOrder.OpenOrder();
        frame.setVisible(false);
        frame.dispose();
      }
    }
void comboFrame()  {
    frame.setPreferredSize(new Dimension(200,100));
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationRelativeTo(null);
    JComponent newContentPane = new opencb();
    newContentPane.setOpaque(true); //content panes must be opaque
    frame.setContentPane(newContentPane);
}


Zecho 24-11-2009 02:35 PM

Re: Close Combo Box in java
 
Hello
I think swing utilities can be helpful here. Using them is very easy and the program will be small. The swing utility I am talking about is SwingUtilities.invokeLater. This should definitely help you.
Code:

SwingUtilities.invokeLater(new Runnable() {
        public void run() {
                openo.openo();
        }
});

If any more queries do post back.

cyber-noob 24-11-2009 02:39 PM

Re: Close Combo Box in java
 
Hi
I said that I need to close the combo box, but really sorry that is not the exact problem. Sorry that I have not explained you in a proper way. I want my program to work something like this, when i open a new project from the main class the combo box should be called so that I can select the project from the list. My problem is when I select a project a new frame is appeared in from of me but the combo box is still in the back ground.


All times are GMT +5.5. The time now is 09:55 AM.