A split button control for Java Swing.
A simple implementation of the split button control for Java Swing. This control raises two events:
buttonClicked(ActionEvent e)splitButtonClicked(ActionEvent e)
The buttonClicked event is raised when the main, or left, part of the button is clicked, which will not trigger the popup menu. The splitButtonClicked event is raised when the split, or right, part of the button is clicked and displays a popup menu.
To handle these events you need a listener that implements:
SplitButtonActionListenerto handle both events in a single listenerButtonClickedActionListenerto handle just buttonClickedSplitButtonClickedActionListenerto handle just splitButtonClicked
See also http://naveedmurtuza.blogspot.ch/2010/11/jsplitbutton.html
//first instantiate the control
JSplitButton splitButton = new JSplitButton();
//register for listener
splitButton.addSplitButtonActionListener(new SplitButtonActionListener() {
public void buttonClicked(ActionEvent e) {
System.out.println("Button Clicked");
}
public void splitButtonClicked(ActionEvent e) {
System.out.println("Split Part Clicked");
}
});
//add popup menu
splitButton.add(popupMenu);
//add this control to panel
panel.add(splitButton);or (using Java 8 lambda expressions):
//first instantiate the control
JSplitButton splitButton = new JSplitButton();
//register for button listener
splitButton.addButtonClickedActionListener((ActionEvent e) -> {
System.out.println("Button Clicked");
});
//register for split button listener
splitButton.addSplitButtonClickedActionListener((ActionEvent e) -> {
System.out.println("Split Part Clicked");
});
//add popup menu
splitButton.add(popupMenu);
//add this control to panel
panel.add(splitButton);- Add the Jitpack repository to
build.gradle
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
- Add the dependency
dependencies {
implementation 'com.github.rhwood:jsplitbutton:Tag'
}
- Add the Jitpack repository to
pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
- Add the dependency
<dependency>
<groupId>com.github.rhwood</groupId>
<artifactId>jsplitbutton</artifactId>
<version>Tag</version>
</dependency>
JSplitButton is supported on Java LTS versions 17, 21, and 25. Non-LTS versions of Java are not supported and will receive best-effort support.
Support for Java versions 8 and 11 is depricated, and CI testing will not be performed on these versions, but source code compatibility will be retained through a minimum of November 2026 for Java 8 and November 2027 for Java 11.
- Add the Jitpack.io repositories shown above
- Change the Group ID in
pom.xmlorbuild.gradlefromcom.alexandriasoftware.swingtocom.github.rhwood.jsplitbutton - Change the package name in imports from
com.alexandriasoftware.swingtocom.github.rhwood.jsplitbutton
- Versions 1.3.1 and newer are released under the Apache 2.0 License
- Version 1.3.0 is released under the GNU Public License 2.0
- Original development by Naveed Quadri in 2012
- Updated by Andreas Kuhtz in 2015


