edu.stanford.nlp.swing
Class ButtonRolloverBorderAdapter

java.lang.Object
  extended byjava.awt.event.MouseAdapter
      extended byedu.stanford.nlp.swing.ButtonRolloverBorderAdapter
All Implemented Interfaces:
EventListener, MouseListener

public class ButtonRolloverBorderAdapter
extends MouseAdapter

MouseListener to only show the border of a button on rollover. A common UI practice, especially in toolbars, is to normally render buttons with their icon/text but no surrounding border, and only to show the border when the mouse is over the button. Java buttons don't normally do this. To enable that behavior, call ButtonRolloverBorderAdapter.manageButton on your button (this only works for subclasses of AbstractButton, i.e. most swing buttons but not AWT). As a convinience, you can also call ButtonRolloverBorderAdapter.manageToolBar to enable this behavior for all buttons on the given toolbar.

Author:
Joseph Smarr (jsmarr@stanford.edu)

Method Summary
static void manageButton(AbstractButton button)
          Adds rollover-border behavior to the given button.
static void manageToolBar(JToolBar toolBar)
          Adds rollover-border behavior to all the buttons in the given toolbar.
 void mouseEntered(MouseEvent e)
          If e.getSource is an AbstractButton, shows its border.
 void mouseExited(MouseEvent e)
          If e.getSource is an AbstractButton, hides its border.
 
Methods inherited from class java.awt.event.MouseAdapter
mouseClicked, mousePressed, mouseReleased
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

manageButton

public static void manageButton(AbstractButton button)
Adds rollover-border behavior to the given button. Specifically, adds a shared instance of ButtonRolloverBorderAdapter as a MouseListener to the given button and turns its border off (otherwise it wouldn't get turned off until the first mouse exit). Also does some other minor UI tweaks like not painting focus and narrowing the margin around the icon (makes it look like toolbar icons in Forte).


manageToolBar

public static void manageToolBar(JToolBar toolBar)
Adds rollover-border behavior to all the buttons in the given toolbar. Convinience method since normally one does this for a set of buttons in a toolbar.

See Also:
manageButton(javax.swing.AbstractButton)

mouseExited

public void mouseExited(MouseEvent e)
If e.getSource is an AbstractButton, hides its border.


mouseEntered

public void mouseEntered(MouseEvent e)
If e.getSource is an AbstractButton, shows its border. Don't show the border if the button is disabled, as this looks bad and is generally not done.



Stanford NLP Group