Results 1 to 5 of 5
  1. #1
    ocean is offline Senior Member
    Join Date
    Sep 2009
    Location
    Sweden/Borås
    Posts
    107
    Rep Power
    0

    Default How to Close Combobox.

    Hello happy ppl.

    Im stuck, how can I close the ComboBox after I have selected an project. It opens the class OpenOrder as it shoud, but the combobox is left open behind the new frame.

    Java Code:
    public OpenComboBox() {
        String[] projectNames = { "2004", "2003", "2005" };
         JComboBox project = new JComboBox(projectNames);
         project.setSelectedIndex(2);
         project.addActionListener(this);
         add(project, BorderLayout.PAGE_START);
         setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
    }
    public void actionPerformed(ActionEvent e) {
           JComboBox cb = (JComboBox)e.getSource();
           String projectNames = (String)cb.getSelectedItem();
           if (projectNames.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 OpenComboBox();
        newContentPane.setOpaque(true); //content panes must be opaque
        frame.setContentPane(newContentPane);
    }
    I have tryed diffrent things in actionPerformed. last thing i tryed was to do a frame.dispose();

    Would be happy if someone can point me in the rigth direction.

    Best Regards / Ocean

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default

    Use SwingUtilities.invokeLater. That should help.

    Java Code:
    SwingUtilities.invokeLater(new Runnable() {
    	public void run() {
    		openOrder.OpenOrder();
    	}
    });
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    ocean is offline Senior Member
    Join Date
    Sep 2009
    Location
    Sweden/Borås
    Posts
    107
    Rep Power
    0

    Default

    Hm how can that close my ComboFrame ?

  4. #4
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default

    Huh?! You've asked how to close the ComboBox.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  5. #5
    ocean is offline Senior Member
    Join Date
    Sep 2009
    Location
    Sweden/Borås
    Posts
    107
    Rep Power
    0

    Default

    Sorry if Im bad at explaning. Yes. When i open a new project from MainClass, ComboFrame calls and i can select project from the list. When i selected a project a new Frame appears. But the comboFrame is still in the background. :)

Similar Threads

  1. close to zero
    By nokicky in forum New To Java
    Replies: 6
    Last Post: 10-26-2009, 05:30 PM
  2. Need Help combobox
    By kwink in forum AWT / Swing
    Replies: 3
    Last Post: 03-21-2009, 11:05 AM
  3. Close but help would be grateful
    By reader34 in forum New To Java
    Replies: 8
    Last Post: 12-21-2008, 06:42 PM
  4. combobox
    By chandu.v in forum New To Java
    Replies: 2
    Last Post: 07-02-2008, 09:36 PM
  5. ComboBox Fix Width
    By Azndaddy in forum New To Java
    Replies: 2
    Last Post: 05-29-2008, 05:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •