Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo Box Popups on Startup

Status
Not open for further replies.

thebarslider

Programmer
Dec 21, 2001
80
GB
Dear All,

I have what sounds like a simple problem but i'm stuck. All i want to do is open a combo box pop so you can view the drop down menu when the dialog is opened. My code is as follows:

this.setVisible(true);
this.showPopupCombo();

Where this is the dialog (this section of code is run inside InitDialog. And the method to show the drop down is:

public void showPopupCombo() {
if (!thingCombo.isPopupVisible()) {
thingCombo.setVisible(true);
thingCombo.setPopupVisible(true);
thingCombo.showPopup();
}
}

This always produces the Exception:

java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location

I understand that this means the component is not visable on the screen, i think this is because i am producing the Dialog box from a listener call on a text field. Although wherever i call the showComboPopup method from i always get the same error.

Hopefully someone can point me in the right direction. Its always the small errors that seem to get me.....Arrggh!

Mark.
 
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class mycom2 extends JFrame implements ActionListener
      {
       String nameList[] = {"Adam","Bob"};
       JComboBox selectName;
       JCheckBox checkName[];
       public mycom2()
              {
               super("JComboBox and checkbox");
               selectName = new JComboBox(nameList);
               getContentPane().setLayout(new GridLayout(21,1));
               getContentPane().add(selectName);
               selectName.addActionListener(this);
              }
       public void actionPerformed(ActionEvent e)
              {

              }
       public static void main(String args[])
              {
               mycom2 mycomObj = new mycom2();
               mycomObj.setSize(400,400);
               mycomObj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
               mycomObj.setVisible(true);
mycomObj.selectName.showPopup();
mycomObj.repaint();
              }
      }
 
yourJFrame.yourDialog.yourCombo.showPopup();
yourJFrame.repaint();
Please post your complete code if you can get it work.
 

Please post your complete code if you cannot get it work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top