Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Drop-Down-Menu in JToolbar

54 views
Skip to first unread message

Thorsten Kiefer

unread,
May 26, 2008, 7:13:25 AM5/26/08
to
Hi,
I've seen drop-down menus in e.g. eclipse, but I don't know how
to create that. It's not possible to add JPopupMenu to JToolbar.

Best Regards
Thorsten

John

unread,
May 27, 2008, 3:27:14 AM5/27/08
to
Thorsten Kiefer a écrit :

> Hi,
> I've seen drop-down menus in e.g. eclipse, but I don't know how
> to create that. It's not possible to add JPopupMenu to JToolbar.

You cann add a MouseListener on JToolbar, so you must be able to show a
popup menu. If isPopupTrigger always return false on JToolbar, you can
show the popup on mouseReleased for example.

Andrew Thompson

unread,
May 27, 2008, 3:48:54 AM5/27/08
to
On May 26, 9:13 pm, Thorsten Kiefer <thorstenkie...@gmx.de> wrote:
...
> ...It's not possible to add JPopupMenu to JToolbar.

Which Java are you using?

Or perhaps I should ask, which JavaDocs are you
*failing* to use?

<sscce>
import javax.swing.*;

class ToolBarWithPopupMenu {

public static void main(String[] args) {
Runnable r = new Runnable() {
public void run() {
JFrame f = new JFrame();

JToolBar tb = new JToolBar();
JPopupMenu popup = new JPopupMenu();
tb.setComponentPopupMenu( popup );

for (int ii=0; ii<4; ii++) {
tb.add( new JButton("" + ii) );
popup.add( "" + ii);
}
f.add( tb );

f.pack();
f.setVisible(true);
}
};
java.awt.EventQueue.invokeLater(r);
}
}
</sscce>

--
Andrew T.
PhySci.org

Rogan Dawes

unread,
Jun 2, 2008, 6:37:23 AM6/2/08
to

Sounds like you don't really want a JPopupMenu, but rather a JComboBox?

Rogan

Evans

unread,
Jun 3, 2008, 7:53:26 AM6/3/08
to

There's a very nice example on how to use JComboBox if that's what
you're after.
http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html

Evans
http://www.onyxtic.com
----
Kettle-Pot-Black

0 new messages