About JSplitButton

A Split Button control for Java Swing.

Maven Central Javadocs Build CodeQL Quality Gate Status Maintainability Rating Coverage

A simple implementation of the split button control for Java Swing. This control raises two events:

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:

See also http://naveedmurtuza.blogspot.ch/2010/11/jsplitbutton.html

Screenshots

alt tag

alt tag

alt tag

Using the Control

//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);

License

Prior History