0

i have jFrame = frame

it have jcombobox = combo

then i have jpanel = panel

i have many component inside this panel

i try to add this panel into combobox popupmenu

so if combobox clicked,

panel that have many components will show up

it is possible to add panel into combobox popup menu?!?!

how to do it???

i already read

http://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html

and

http://docs.oracle.com/javase/tutorial/uiswing/examples/components/ComboBoxDemoProject/src/components/ComboBoxDemo.java

but still not have any clue

how to do it?

thankz a lot for any help...

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Jason Amavisca
  • 187
  • 3
  • 5
  • 13
  • Welcome to the forum :-) Just ... imagine yourself stepping into my shoes for a moment and read your own question with my eyes: would you be happy or at least understand what you are writing about? – kleopatra Oct 10 '12 at 07:48

1 Answers1

0

So from your description, you have a panel that is not visible, that you would like to appear if the combobox is clicked? So it will appear for any option in the combobox?

That should be simple enough. Lets modify the JLabel in this ComboBoxDemo from the Java Tutorials. Since they both inherit from JComponent, we will be able to make the JLabel and the JPanel visible in the same way.

First, make sure you understand what the demo is doing. The Combobox options are changing the format of the date's text in the JLabel. We want to edit the demo in such a way that this JLabel is not visible until after we select any option in our JComboBox.

First, we will want to include a boolean as a class variable, so that we can access it in any of our methods.

boolean visibleComp;

Next, in the constructor, you will want to change the JLabel "result" to be invisible by default. We can do this by using the setVisible method of the JComponent.

result.setVisible(false);

Now we need to control when and how result becomes visible -- as we continue through the code, we see that the actionPerformed method handles our events, and passes the formatting details off to another method called reformat.

Since reformat is also called in our constructor, we will want to set our boolean value in the actionPerformed method.

visibleComp = true;

We will then want to add a conditional statement to the try block in reformat -- this will check to see if our boolean is true, which would only occur if an action had been performed by the user. We can use this to set our component's visibility.

if(visibleComp){
     result.setVisible(true);
}

You can easily interchange a JPanel with this example. Hope that helps.

Anthony Neace
  • 25,013
  • 7
  • 114
  • 129
  • thankz for the help,but.. i not select an item in combobox, the combobox not have any item, i just want if combobox popupmenu listener is visible(triggered),the popup menu will show my panel that have many jlabel.. then if jlabel clicked.. combobox will add item(String) from that jlabel... by the way.. besides adding a jpanel to combobox popupmenu.. i can do this with .... if combobox popup is visible is triggered,i setVisible(false) for jcombobox popupmenu.. then set visible(true) for other popupmenu that have my panel.. how i setVisible(false) for my combobox popupMenu? thanks for any help – Jason Amavisca Oct 10 '12 at 06:22