JComboButton?

  • Thread starter Brian J. Sayatovic
  • Start date
B

Brian J. Sayatovic

I'm looking for a swing button class that will act like the "view"
toolbar button in Explorer. It has a drop-down arrow embedded on its
right that, when specifically clicked, will display a drop down of
actions. When the remainder of the button is pressed, the default
action (one of those in the list) is performed.

Now, I've built something like this myself, already. It's a JPAnel
subclass that has two JButtons in it: a JButton with a settable Action
abd a drop-down arrow button. However, this is not the same
experience as using a real combo button. The borders must operate as
one.

I've started investigating how a JButton's borders are handled, but it
seems to be a maze of pluggable look and feel ComponentUI subclasses.
It is very frutrating. Every Swing tutorial I've checked out has
glossed over how the existing implementations work.

My other thought was to simply paint the component myself, but, there
is a lot of platform-specific logic behidn the painting of each
button. I don't want to duplicate that myself, and can't find a good
resource on how to take advantage of the PLAF work.

Any ideas on any of these fronts?

Regards,
Brian.
 
T

Thomas Weidenfeller

I'm looking for a swing button class that will act like the "view"
toolbar button in Explorer. It has a drop-down arrow embedded on its
right that, when specifically clicked, will display a drop down of
actions. When the remainder of the button is pressed, the default
action (one of those in the list) is performed.

Sounds like you want to have what is called a "Drop-down Menu in a
Toolbar Button" in the Java GUI style guide:

http://java.sun.com/products/jlf/ed2/book/HIG.Menus4.html#44052

Last time I looked, Swing didn't come with a ready to use
implementation. A year ago I posted an implementation in
comp.lang.java.gui (a group better suited for GUI questions). Maybe 25
lines of code. See

http://groups.google.com/[email protected]

Note the usage of the popup menu for, aehm, getting the behavior of a
menu :)

If you want to have the Windows-style version of such a toolbar button,
you need to place two normal buttons:n a row: one for the default
behavior, one for droping down the menu.

/Thomas
 
B

Brian J. Sayatovic

Yes, I concur with what you said with a few small, but tedious
exceptions. I've already got two buttons side-by-side (and I have
those in a JPanel so they can be added as a single item). The problem
is in manipulating their borders.

The way I've seen these drop-down buttons work is that mousing-over
either raises the whole button (at least on Windows). Having two
buttons side-by-side won't give me that. I'd have to attach
mouse-listeners to each, and string them each other.

But that is where I started running into problems. To make a true
JComboButton class, it shoudl adhere to the pluggable look-and-feel.
My idea is to simply have them operate as two buttons strung together.
But while I can capture the mouseOver event, for example, on one, how
to I also send that event to the other? I need the constituent
buttons to actually handle the event to make it delegate to the proper
ComponentUI installed by the look-and-feel in use.

I'll re-think this into a cleaerer post and re-post to the gui group,
as you suggested.

Regards,
Brian.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top