Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JComboButton?

Reply
Thread Tools

JComboButton?

 
 
Brian J. Sayatovic
Guest
Posts: n/a
 
      07-01-2003
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.
 
Reply With Quote
 
 
 
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      07-01-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) (Brian J. Sayatovic) writes:
> 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...us4.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/groups?selm...oo.ericsson.se

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
 
Reply With Quote
 
 
 
 
Brian J. Sayatovic
Guest
Posts: n/a
 
      07-01-2003
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.


(E-Mail Removed)lid (Thomas Weidenfeller) wrote in message news:<bdrds2$kpu$(E-Mail Removed)>. ..
> (E-Mail Removed) (Brian J. Sayatovic) writes:
> > 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...us4.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/groups?selm...oo.ericsson.se
>
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments