Giter Club home page Giter Club logo

jsplitbutton's Introduction

JSplitButton

A split button control for Java Swing.

Maven Central Javadocs Build CodeQL Quality Gate Status Maintainability Rating codecov OpenSSF Scorecard

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:

  • SplitButtonActionListener to handle both events in a single listener
  • ButtonClickedActionListener to handle just buttonClicked
  • SplitButtonClickedActionListener to handle just splitButtonClicked

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

Migrating from Version 1.x to 2.0 or Newer

  1. Update repositories (version 1.x was published at Maven Central, version 2.0 or newer are published at GitHub Packages and Jitpack.io)
  2. Change the Group ID in Maven from com.alexandriasoftware.swing to com.github.rhwood.jsplitbutton
  3. Change the package name in imports from com.alexandriasoftware.swing to com.github.rhwood.jsplitbutton

Prior History

jsplitbutton's People

Contributors

akuhtz avatar dependabot-preview[bot] avatar dependabot[bot] avatar naveedmurtuza avatar rhwood avatar step-security-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

jsplitbutton's Issues

Rename package tree

Since I no longer control alexandriasoftware.com, the package needs to be renamed from com.alexandriasoftware.swing.jsplitbutton to com.github.rhwood.jsplitbutton to reflect that.

Add 1.3 -> 2.0 migration instructions

When preparing to publish version 2.0.0, documentation needs to cover migrating from 1.3.1 to 2.0.0.

The following documentation needs to be updated

  • README.md
  • Website
  • Javadocs

Size doesn't display correctly when text is listed below image

Hi,

I just wanted to report this before I forgot. I wanted to create a drop-down button in a toolbar.

My current toolbar buttons shows icons primarily with the label listed below -- like this:
image

The last item "Custom" is trying to use this library to show a drop-down menu. But, as you can see the button size isn't large enough to cover the image and dropdown arrow.

Is this something I'm doing wrong or is this button just not meant to work this way? If it's an easy fix I can look at making it but wanted to get your $.02 first

                Image icon = loadImage("icon_script.png");
                JSplitButton button = new JSplitButton(new ImageIcon(icon));
                button.setText("Custom");
                button.setFont(new Font(Font.SERIF, Font.PLAIN, 10));
                button.setToolTipText("View custom scripts");
                button.setVerticalTextPosition(SwingConstants.BOTTOM);
                button.setHorizontalTextPosition(SwingConstants.CENTER);
                button.setPopupMenu(popup);
                toolbar.add(button);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.