Click to See Complete Forum and Search --> : JComboBox with hidden submenus


Larsp
April 7th, 2004, 05:37 AM
Hi! I would like to have a JComboBox or something like it with hidden submenus that shows when you click on the main subject.

Something like how JMenu works, but I want to display it on the page and not up on a boarder.

dlorde
April 7th, 2004, 09:12 AM
JMenu, JMenuItem, and JMenuBar are all just Components (JMenu, JMenuItem are AbstractButtons), so why not use them? They don't have to be displayed at the top of the frame.

If it walks like a duck...

Larsp
April 7th, 2004, 10:23 AM
Thanks! But how do you do it, can you place a jmenu and jmenuItem in a JCombobox?

Tried this, it shows but it doesn't work. You can see "trees" but not "christmastree".

jmTest = new JMenu("Trees");
c.add(jmTest);
//c is my contentpane
jmTest2 = new JMenuItem("Christmas tree");
jmTest.setBounds(470, 450, 300, 100);
jmTest.add(jmTest2);

ats007spdou
April 8th, 2004, 01:18 AM
Hi Larsp, usually one doesn't do what you're asking. However, you can try to put a JComboBox inside a JComboBox(Note, I've never tried this, it might work).

I can't test(right now) the idea fully because I have to run......

Play around with what you can do and can't, java is a pretty flexible language.......

cjard
April 8th, 2004, 04:23 AM
er, as far as i was aware, nearly every complicated java component is built up of simpler ones..

e.g. a JComboBox could be conceptualised as a JTextField and a JButton inside a JPanel.. CLicking the button pops down a menu, that is actually a panel (drawn on a different layer) of text display components, maybe jlabels or possibly buttons with no border..

End of the day, seeing as every java GUI component inherits from JComponent (in swing at least), it should be possible to extend the capabilities of any native component, by replacing the JComponents that it draws, with other JComponents

A good person to ask, would be codeguru forum member Viravan.. he seems very keen on extending and creating custom components or shoehorning the existing ones into doing what he wants... If you search for posts by him, some of them will have reference to his website where you can get source code and ideas, or contact him

dlorde
April 8th, 2004, 06:31 AM
What about using a JPopupMenu? See Bringing up a Popup Menu (http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html#popup).

It's easy to overlook the obvious...

sheppyc
April 9th, 2004, 05:43 AM
yer i was gonna suggest that...

cjard
April 9th, 2004, 06:21 AM
Originally posted by sheppyc
yer i was gonna suggest that...

"me too"