Java Code Examples for javax.swing.AbstractButton#addMouseListener()

The following examples show how to use javax.swing.AbstractButton#addMouseListener() . 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: TransparentToolBar.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void addItem(JComponent c) {
    c.setOpaque(false);

    if (c instanceof JButton)
        ((JButton)c).setDefaultCapable(false);

    if (toolbar != null) {
        toolbar.add(c);
    } else {
        add(c);
        if (c instanceof AbstractButton) {
            AbstractButton b = (AbstractButton) c;
            b.addMouseListener(listener);
            b.addChangeListener(listener);
            b.addFocusListener(listener);
            b.setRolloverEnabled(true);
        }
    }
}
 
Example 2
Source File: TransparentToolBar.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
public void addItem(JComponent c) {
    c.setOpaque(false);

    if (c instanceof JButton)
        ((JButton)c).setDefaultCapable(false);

    if (toolbar != null) {
        toolbar.add(c);
    } else {
        add(c);
        if (c instanceof AbstractButton) {
            AbstractButton b = (AbstractButton) c;
            b.addMouseListener(listener);
            b.addChangeListener(listener);
            b.addFocusListener(listener);
            b.setRolloverEnabled(true);
        }
    }
}
 
Example 3
Source File: NbEditorToolBar.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void processButton(AbstractButton button) {
    removeButtonContentAreaAndBorder(button);
    button.setMargin(BUTTON_INSETS);
    if (button instanceof AbstractButton) {
        button.addMouseListener(sharedMouseListener);
    }
    //fix of issue #69642. Focus shouldn't stay in toolbar
    button.setFocusable(false);
}
 
Example 4
Source File: DataViewUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void processButton(AbstractButton button) {
    button.setContentAreaFilled(false);
    button.setBorderPainted(false);
    button.setMargin(BUTTON_INSETS);
    if (button instanceof AbstractButton) {
        button.addMouseListener(sharedMouseListener);
    }
    //Focus shouldn't stay in toolbar
    button.setFocusable(false);
}
 
Example 5
Source File: TransparentToolBar.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public Component addItem(Component c, int index) {
    if (c instanceof JComponent)
        ((JComponent)c).setOpaque(false);

    if (c instanceof JButton)
        ((JButton)c).setDefaultCapable(false);
    
    if (UISupport.isAquaLookAndFeel() && c instanceof AbstractButton)
        ((AbstractButton)c).putClientProperty("JButton.buttonType", "gradient"); // NOI18N

    if (toolbar != null) {
        toolbar.add(c, index);
    } else {
        add(c, index);
        if (c instanceof AbstractButton) {
            AbstractButton b = (AbstractButton) c;
            b.addMouseListener(listener);
            b.addChangeListener(listener);
            b.addFocusListener(listener);
            b.setRolloverEnabled(true);
            listener.refresh(b);
        }
    }
    repaint();
    
    return c;
}
 
Example 6
Source File: JButtonFactory.java    From WorldGrower with GNU General Public License v3.0 5 votes vote down vote up
private static void addClickSoundEffect(SoundIdReader soundIdReader, AbstractButton button) {
	if (soundIdReader == null) {
		throw new IllegalStateException("soundIdReader is null");
	}
	
	button.addMouseListener(new MouseAdapter() {
		@Override
           public void mousePressed(MouseEvent e) {
           	soundIdReader.playSoundEffect(SoundIds.CLICK);
           }
       });
}
 
Example 7
Source File: ToolButtonFactory.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private static void configure(AbstractButton button) {

        RolloverButtonEventListener l = new RolloverButtonEventListener();
        button.addMouseListener(l);
        button.addItemListener(l);

        if (button.getAction() != null) {
            if (button.getIcon() != null) {
                button.putClientProperty("hideActionText", Boolean.TRUE);
            }
            Object largeIcon = button.getAction().getValue("_largeIcon");
            if (largeIcon instanceof Icon) {
                button.setIcon((Icon) largeIcon);
            }
        }

        Icon icon = button.getIcon();
        int minWidth = BUTTON_MIN_SIZE;
        int minHeight = BUTTON_MIN_SIZE;
        if (icon != null) {
            button.setText(null);
            minWidth = Math.max(icon.getIconWidth(), BUTTON_MIN_SIZE);
            minHeight = Math.max(icon.getIconHeight(), BUTTON_MIN_SIZE);
            if (icon instanceof ImageIcon) {
                button.setRolloverIcon(createRolloverIcon((ImageIcon) icon));
            }
        } else {
            button.setText("[?]");
        }
        final int space = 3;
        Dimension prefSize = new Dimension(minWidth + space, minHeight + space);
        Dimension minSize = new Dimension(minWidth, minHeight);
        Dimension maxSize = new Dimension(minWidth + space, minHeight + space);
        button.setPreferredSize(prefSize);
        button.setMaximumSize(maxSize);
        button.setMinimumSize(minSize);

    }
 
Example 8
Source File: SlideGestureRecognizer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Attaches given button to this recognizer, it means starts listening
 * on its various mouse and action events
 */
public void attachButton (AbstractButton button) {
    button.addActionListener(this);
    button.addMouseListener(this);
    button.addMouseMotionListener(this);
}
 
Example 9
Source File: SearchButton.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static void processButton(AbstractButton button) {
    removeButtonContentAreaAndBorder(button);
    button.setMargin(BUTTON_INSETS);
    button.addMouseListener(sharedMouseListener);
    button.setFocusable(false);
}
 
Example 10
Source File: BasicLinkButtonUI.java    From orbit-image-analysis with GNU General Public License v3.0 4 votes vote down vote up
protected void installListeners(AbstractButton b) {
  super.installListeners(b);
  b.addMouseListener(handCursorListener);
}
 
Example 11
Source File: FloatingButtonEnabler.java    From ccu-historian with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Adds a button to this enabler.
 *
 * @param button  the button.
 */
public void addButton(final AbstractButton button) {
    button.addMouseListener(this);
    button.setBorderPainted(false);
}
 
Example 12
Source File: FloatingButtonEnabler.java    From ccu-historian with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Removes a button from the enabler.
 *
 * @param button  the button.
 */
public void removeButton(final AbstractButton button) {
    button.addMouseListener(this);
    button.setBorderPainted(true);
}