10 Replies Latest reply: Jan 7, 2005 11:23 AM by 807596 RSS

    why JComboBox not shown?

    807596
      I use a JPanel, and tried to show a JComboBox on it.
      But somehow the JComboBox is not shown. Need
      help here. Thank you.
        • 1. Re: why JComboBox not shown?
          807596
          Show us the code. It's impossible to say what the problem is from your description.
          • 2. Re: why JComboBox not shown?
            807596
            It is not that the JComboBox is not shown, but it is not shown correctly since
            the down-pointing solid triangle is not shown and the JComboBox is not
            activated until I moved the mouse pointer to a different area or clicked the
            mouse. I did use setEnabled(true). Here is the code:
                modeType.addItem("Phi");
                modeType.addItem("Pump_probe delay");
                modeType.setSelectedIndex(0);
                modeType.setEnabled(true);
            
                delayMode.setBounds(167, 210, 90, 30);
                add(delayMode, null);
            • 3. Re: why JComboBox not shown?
              807596
              Error in my previous code. The right one is:
                  modeType.addItem("Phi");
                  modeType.addItem("Pump_probe delay");
                  modeType.setSelectedIndex(0);
                  modeType.setEnabled(true);
              
                  modeType.setBounds(40, 150, 120, 30);
                  add(modeType, null);
              • 4. Re: why JComboBox not shown?
                807596
                Well, that little code snippet is pretty useless without its context. I guess modeType is your combobox, yes? What are you adding it to? And why are you setting its bounds, have you set the Layout Manager to null? Why?
                • 5. Re: why JComboBox not shown?
                  807596
                  modeType is my jCOmboBox, and the layoutManage is set to null.
                  • 6. Re: why JComboBox not shown?
                    807596
                    Just for fun, I wrote a small test program that included the following lines:
                    modeType.addItem("Phi");
                    modeType.addItem("Pump_probe delay");
                    modeType.setSelectedIndex(0);
                    modeType.setEnabled(true);
                    
                    modeType.setBounds(40, 150, 120, 30);
                    add(modeType, null);
                    As you can see, those lines are identical to the code you posted. modeType is a JComboBox that I'm adding to a JPanel that has no layout manager. In my program the combobox shows up perfectly.

                    This tells us that the problem with your code is not those 6 lines, but something else. And without seeing the rest of your code it's awfully difficult to guess what it can be.
                    • 7. Re: why JComboBox not shown?
                      807596
                      Try maximizing your frame or anything else.
                      • 8. Re: why JComboBox not shown?
                        807596
                        If I run the program alone (changed from JPanel to JFrame), the JComboBox
                        does show the down-pointing triangle. Problaby my other programs cost
                        the problem of not showing. Thank you for your interest.
                        • 9. Re: why JComboBox not shown?
                          807596
                          I have found that after I click mouse once anywhere in the displayed area (the outer most--large),
                          the down-pointing triangle is shown. So is this a Java bug?
                          • 10. Re: why JComboBox not shown?
                            807596
                            So is this a Java bug?
                            Probably not. My money would be on that the bug is in your code. But you won't show us your code so who knows?