Example usage for javax.swing JComponent setFocusable

List of usage examples for javax.swing JComponent setFocusable

Introduction

In this page you can find the example usage for javax.swing JComponent setFocusable.

Prototype

public void setFocusable(boolean focusable) 

Source Link

Document

Sets the focusable state of this Component to the specified value.

Usage

From source file:Main.java

/**
 * Sets focusable state of component and all of its children.
 *
 * @param component/*from  www  . j  ava 2 s  .  c  o m*/
 *            component to modify
 * @param focusable
 *            whether component is focusable or not
 * @param childsOnly
 *            whether exclude component from changes or not
 */
public static void setFocusableRecursively(final JComponent component, final boolean focusable,
        final boolean childsOnly) {
    if (!childsOnly) {
        component.setFocusable(focusable);
    }
    for (int i = 0; i < component.getComponentCount(); i++) {
        if (component.getComponent(i) instanceof JComponent) {
            setFocusableRecursively((JComponent) component.getComponent(i), focusable, false);
        }
    }
}

From source file:cool.pandora.modeller.ui.BagTableFormBuilder.java

/**
 * addBinding./* w ww .j a  v  a  2  s.c  o m*/
 *
 * @param isRequired   boolean
 * @param labelName    String
 * @param component    JComponent
 * @param removeButton JComponent
 * @return JComponent
 */
private JComponent[] addBinding(final boolean isRequired, final String labelName, final JComponent component,
        final JComponent removeButton) {
    removeButton.setFocusable(false);
    final JLabel label = new JLabel(labelName); // createLabelFor(fieldName,
    // component);
    label.setToolTipText("Double-Click to Edit");
    final TableLayoutBuilder layoutBuilder = getLayoutBuilder();
    if (!layoutBuilder.hasGapToLeft()) {
        layoutBuilder.gapCol();
    }
    layoutBuilder.cell(label, "colSpec=left:pref:noGrow");
    final JComponent reqComp;
    /* */
    if (isRequired) {
        final JButton b = new JButton("R");
        b.setForeground(Color.red);
        b.setOpaque(false);
        b.setBorderPainted(false);
        reqComp = b;
    } else {
        final JButton b = new JButton("");
        b.setOpaque(false);
        b.setBorderPainted(false);
        reqComp = b;
    }
    /* */
    reqComp.setFocusable(false);
    layoutBuilder.cell(reqComp, "colSpec=left:pref:noGrow");
    layoutBuilder.cell(component, "colSpec=fill:pref:grow");
    layoutBuilder.labelGapCol();
    layoutBuilder.cell(removeButton, "colSpec=left:pref:noGrow");
    layoutBuilder.labelGapCol();
    return new JComponent[] { label, reqComp, component, removeButton };
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopFilterHelper.java

@Override
public void setComponentFocusable(Component component, boolean focusable) {
    JComponent dComponent = DesktopComponentsHelper.unwrap(component);
    dComponent.setFocusable(focusable);
}