JComboButton?

Discussion in 'Java' started by Brian J. Sayatovic, Jul 1, 2003.

  1. 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.
    Brian J. Sayatovic, Jul 1, 2003
    #1
    1. Advertising

  2. (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/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/groups?selm=akvn4d$eb0$

    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
    Thomas Weidenfeller, Jul 1, 2003
    #2
    1. Advertising

  3. 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.


    lid (Thomas Weidenfeller) wrote in message news:<bdrds2$kpu$>...
    > (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/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/groups?selm=akvn4d$eb0$
    >
    > 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
    Brian J. Sayatovic, Jul 1, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page