[fixes #989] Fix toggleButton going 'blank' upon window out of focus
This commit is contained in:
parent
2f6a8c8db9
commit
716e723a53
@ -35,12 +35,12 @@ public class SelectColorButton extends JButton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addChangeListenerSelectColor() {
|
private void addChangeListenerSelectColor() {
|
||||||
|
if (UIManager.getColor("Button.selectForeground") == null
|
||||||
|
|| UIManager.getColor("Button.foreground") == null)
|
||||||
|
return;
|
||||||
addChangeListener(new ChangeListener() {
|
addChangeListener(new ChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void stateChanged(ChangeEvent e) {
|
public void stateChanged(ChangeEvent e) {
|
||||||
if (UIManager.getColor("Button.selectForeground") == null
|
|
||||||
|| UIManager.getColor("Button.foreground") == null)
|
|
||||||
return;
|
|
||||||
if (getModel().isArmed()) {
|
if (getModel().isArmed()) {
|
||||||
setForeground(UIManager.getColor("Button.selectForeground"));
|
setForeground(UIManager.getColor("Button.selectForeground"));
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,8 @@ import javax.swing.JToggleButton;
|
|||||||
import javax.swing.Action;
|
import javax.swing.Action;
|
||||||
import javax.swing.Icon;
|
import javax.swing.Icon;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.event.ChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
import javax.swing.event.ChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
import java.awt.Graphics;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.event.MouseEvent;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is a replacement for the standard JToggleButton. Its purpose is to be able
|
* This class is a replacement for the standard JToggleButton. Its purpose is to be able
|
||||||
@ -57,13 +53,34 @@ public class SelectColorToggleButton extends JToggleButton {
|
|||||||
addChangeListenerSelectColor();
|
addChangeListenerSelectColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method sets the foreground color of the button. If the button is selected, then the selectForeground is used.
|
||||||
|
* If the frame that the button is in goes out of focus or if the button is unselected, then the foreground is used.
|
||||||
|
*
|
||||||
|
* This is to fix an issue on OSX devices where the foreground color would be black on blue (hardly readable)
|
||||||
|
*/
|
||||||
private void addChangeListenerSelectColor() {
|
private void addChangeListenerSelectColor() {
|
||||||
addChangeListener(new ChangeListener() {
|
if (UIManager.getColor("ToggleButton.selectForeground") == null
|
||||||
|
|| UIManager.getColor("ToggleButton.foreground") == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Case: frame goes out of focus
|
||||||
|
addPropertyChangeListener("Frame.active", new PropertyChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void stateChanged(ChangeEvent e) {
|
public void propertyChange(PropertyChangeEvent evt) {
|
||||||
if (UIManager.getColor("ToggleButton.selectForeground") == null
|
if (isSelected() && (boolean)evt.getNewValue()) {
|
||||||
|| UIManager.getColor("ToggleButton.foreground") == null)
|
setForeground(UIManager.getColor("ToggleButton.selectForeground"));
|
||||||
return;
|
}
|
||||||
|
else {
|
||||||
|
setForeground(UIManager.getColor("ToggleButton.foreground"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Case: button is clicked
|
||||||
|
addPropertyChangeListener("ancestor", new PropertyChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void propertyChange(PropertyChangeEvent evt) {
|
||||||
if (isSelected()) {
|
if (isSelected()) {
|
||||||
setForeground(UIManager.getColor("ToggleButton.selectForeground"));
|
setForeground(UIManager.getColor("ToggleButton.selectForeground"));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user