/**
* give a button the correct size, border and rollover behavior
* to emulate an IDEA button.
*
* @param theButton - the JButton to modify
* @param isIcon - is this button an icon or text button.. icons will be sized at
* 24x24 while text buttons will have a width of font point size
* multiplied by text length, and a height of 24.
*/
private void setButtonBehavior(JButton theButton, boolean isIcon) {
// icon is always 24x24...
if (isIcon) {
theButton.setPreferredSize(new Dimension(24, 24));
} else {
int points = theButton.getFont().getSize();
int length = theButton.getText().length();
// width of text buttons... this formula sucks...
theButton.setPreferredSize(new Dimension((points * length), 24));
}
theButton.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
theButton.setFocusPainted(false);
theButton.addMouseListener(new MouseAdapter() {
private final Color EXIT_COLOR = new Color(214, 211, 206);
private final Color ENTER_COLOR = new Color(40, 40, 100);
private final Color ENTER_BORDER_COLOR = new Color(130, 130, 170);
public void mouseEntered(MouseEvent e) {
JComponent jComponent = ((JComponent) e.getSource());
// if this button is active...
if (jComponent.isEnabled()) {
// background color for roll over effect... needs tuning
jComponent.setBackground(ENTER_BORDER_COLOR);
// border color on roll over... needs tuning
jComponent.setBorder(BorderFactory.createLineBorder(ENTER_COLOR, 1));
}
}
public void mouseExited(MouseEvent e) {
JComponent jComponent = ((JComponent) e.getSource());
jComponent.setBackground(EXIT_COLOR);
jComponent.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
}
});
}