Show EnabledLabel.java syntax highlighted
/*
* Copyright (c) 2007
* Helsinki Institute of Physics
* see LICENSE file for details
*
* EnabledLabel.java
*/
package fi.hip.gb.client.ui;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JComponent;
import javax.swing.JLabel;
/**
* A label which will change its color according to the attached component's state.
* When component is enabled, label uses its foreground color, otherwise it's displayed
* in dimmed color (gray). Constructor assumes, that the component is currently
* in enabled state.
*
* @author Juho Karppinen
*/
public class EnabledLabel extends JLabel {
private static final long serialVersionUID = 2628839786733150897L;
/** the component to be enabled/disabled */
private JComponent component;
/**
* Creates a new EnabledLabel which will change its color
* according to the attached component's state. When component
* is enabled, label uses its foreground color, otherwise it's displayed
* in dimmed color (gray). Constructor assumes, that the component is currently
* in enabled state.
* @param compToFollow component which color will be changed
* @param labelText text for the label
**/
public EnabledLabel(JComponent compToFollow, String labelText) {
super(labelText);
component = compToFollow;
component.addPropertyChangeListener(new PropertyListener());
}
private class PropertyListener implements PropertyChangeListener {
public void propertyChange(PropertyChangeEvent e) {
setEnabled(component.isEnabled());
}
}
}
See more files for this project here