Java Code Examples for javafx.scene.control.ButtonBase#isFocused()

The following examples show how to use javafx.scene.control.ButtonBase#isFocused() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SlideCheckBoxBehavior.java    From JFX8CustomControls with Apache License 2.0 6 votes vote down vote up
/**
 * Invoked when a mouse press has occurred over the button. In addition to
 * potentially arming the Button, this will transfer focus to the button
 */
@Override public void mousePressed(MouseEvent e) {
    final ButtonBase button = getControl();
    super.mousePressed(e);
    // if the button is not already focused, then request the focus
    if (! button.isFocused() && button.isFocusTraversable()) {
        button.requestFocus();
    }

    // arm the button if it is a valid mouse event
    // Note there appears to be a bug where if I press and hold and release
    // then there is a clickCount of 0 on the release, whereas a quick click
    // has a release clickCount of 1. So here I'll check clickCount <= 1,
    // though it should really be == 1 I think.
    boolean valid = (e.getButton() == MouseButton.PRIMARY &&
        ! (e.isMiddleButtonDown() || e.isSecondaryButtonDown() ||
            e.isShiftDown() || e.isControlDown() || e.isAltDown() || e.isMetaDown()));

    if (! button.isArmed() && valid) {
        button.arm();
    }
}
 
Example 2
Source File: SlideCheckBoxBehavior.java    From JFX8CustomControls with Apache License 2.0 5 votes vote down vote up
/***************************************************************************
 *                                                                         *
 * Focus change handling                                                   *
 *                                                                         *
 **************************************************************************/

@Override protected void focusChanged() {
    // If we did have the key down, but are now not focused, then we must
    // disarm the button.
    final ButtonBase button = getControl();
    if (keyDown && !button.isFocused()) {
        keyDown = false;
        button.disarm();
    }
}