下面列出了javax.swing.AbstractButton#addMouseListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
}
}
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);
}
}
}
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);
}
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);
}
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;
}
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);
}
});
}
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);
}
/** 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);
}
private static void processButton(AbstractButton button) {
removeButtonContentAreaAndBorder(button);
button.setMargin(BUTTON_INSETS);
button.addMouseListener(sharedMouseListener);
button.setFocusable(false);
}
protected void installListeners(AbstractButton b) {
super.installListeners(b);
b.addMouseListener(handCursorListener);
}
/**
* Adds a button to this enabler.
*
* @param button the button.
*/
public void addButton(final AbstractButton button) {
button.addMouseListener(this);
button.setBorderPainted(false);
}
/**
* Removes a button from the enabler.
*
* @param button the button.
*/
public void removeButton(final AbstractButton button) {
button.addMouseListener(this);
button.setBorderPainted(true);
}