|
|
| Changed: |
< < |
Dimension oldSize = theButton.getPreferredSize();
// icon is always 24x24... but we can be flexible with the text item's width
| > > |
// icon is always 24x24...
|
| Changed: |
< < |
private Color oldColor = null;
| > > |
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);
|
| Changed: |
< < |
oldColor = jComponent.getBackground();
| > > |
// if this button is active...
if (jComponent.isEnabled()) {
|
| Changed: |
< < |
jComponent.setBackground(new Color(130,130,170));
| > > |
jComponent.setBackground(ENTER_BORDER_COLOR);
|
| Changed: |
< < |
jComponent.setBorder(BorderFactory?.createLineBorder(new Color(40,40,100), 1));
| > > |
jComponent.setBorder(BorderFactory?.createLineBorder(ENTER_COLOR, 1));
}
|
| Changed: |
< < |
jComponent.setBackground(oldColor);
| > > |
jComponent.setBackground(EXIT_COLOR);
|
| Added: |
> > |
updated... this version behaves a bit better... |
|
|
| Added: |
> > |
%META:TOPICINFO{author="DanBachelder" date="1024546804" format="1.0" version="1.1"}%
this code (with some work) will help you create buttons that resemble the buttons used in IDEA... if you can't use or don't want to use AnAction?..
/**
* 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) {
Dimension oldSize = theButton.getPreferredSize();
// icon is always 24x24... but we can be flexible with the text item's width
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 Color oldColor = null;
public void mouseEntered(MouseEvent e) {
JComponent jComponent = ((JComponent)e.getSource());
oldColor = jComponent.getBackground();
// background color for roll over effect... needs tuning
jComponent.setBackground(new Color(130,130,170));
// border color on roll over... needs tuning
jComponent.setBorder(BorderFactory.createLineBorder(new Color(40,40,100), 1));
}
public void mouseExited(MouseEvent e) {
JComponent jComponent = ((JComponent)e.getSource());
jComponent.setBackground(oldColor);
jComponent.setBorder(BorderFactory.createEmptyBorder(1,1,1,1));
}
});
}
-- DanBachelder - 20 Jun 2002 |
View
| Diffs | r1.2 | > | r1.1
| More
|
|