7

I need to create a button like this in Java:

ContextMenuButton

You can click on the left part of the button for a normal button action and you can click on the arrow on the right to open a drop down menu.

Is it possible to create something like this in java? Thanks!

Peter Lang
  • 54,264
  • 27
  • 148
  • 161
bw2801
  • 321
  • 2
  • 8
  • 15

1 Answers1

7

In this tutorial the writer shows how to create a button and have a drop down appear next to it when it is clicked. This looks a lot like what you try to achieve. Hope this helps.

http://java.dzone.com/news/drop-down-buttons-swing-new-al

The split button might provide a simpler solution if the Gnu Lesser GPL is ok for you

http://code.google.com/p/jsplitbutton/

gebirgsbärbel
  • 2,327
  • 1
  • 22
  • 38
  • Yes but I wanted that you can click on the button and it performs an action for example save a file to a predefined folder and when you click on the arrow you can choose sub-options like "save as..." or "save and share" or something. When this isn't possible I'll use your solution. – bw2801 Mar 28 '13 at 12:07
  • 1
    there are two ways to achieve this. Either use two buttons and restyle them, or what is probably simpler use the jsplitbutton class on google code (be sure to check that the license is ok for your user scenario) http://code.google.com/p/jsplitbutton/ – gebirgsbärbel Mar 28 '13 at 12:53
  • If you download source, it may not work. Refer this one (http://stackoverflow.com/questions/11646290/splitbutton-in-java) and update the source to make it work. – Tamil Dec 08 '16 at 14:07