Browse Source

Ensure JSpinner has the correct background when first installed.

pull/214/head
weisj 4 years ago
parent
commit
59efefe7a9
  1. 3
      core/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerListener.java
  2. 7
      core/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerUI.java
  3. 10
      core/src/test/java/ui/spinner/SpinnerDemo.java

3
core/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerListener.java

@ -32,7 +32,6 @@ import java.beans.PropertyChangeListener;
import javax.swing.*;
import com.github.weisj.darklaf.util.PropertyKey;
import com.github.weisj.darklaf.util.PropertyUtil;
public class DarkSpinnerListener extends MouseAdapter
implements PropertyChangeListener, FocusListener, SpinnerConstants {
@ -94,7 +93,7 @@ public class DarkSpinnerListener extends MouseAdapter
spinner.revalidate();
spinner.repaint();
} else if (PropertyKey.ENABLED.equals(key)) {
PropertyUtil.installBackground(spinner, spinner.isEnabled() ? ui.background : ui.inactiveBackground);
ui.updateBackground();
}
}
}

7
core/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerUI.java

@ -35,6 +35,7 @@ import com.github.weisj.darklaf.components.ArrowButton;
import com.github.weisj.darklaf.delegate.LayoutManagerDelegate;
import com.github.weisj.darklaf.graphics.PaintUtil;
import com.github.weisj.darklaf.util.PropertyKey;
import com.github.weisj.darklaf.util.PropertyUtil;
/**
* @author Konstantin Bulenkov
@ -84,6 +85,7 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements SpinnerConstants {
arrowUpInactiveIcon = UIManager.getIcon("Spinner.arrowUpInactive.icon");
minusInactiveIcon = UIManager.getIcon("Spinner.minusInactive.icon");
plusInactiveIcon = UIManager.getIcon("Spinner.plusInactive.icon");
updateBackground();
LookAndFeel.installProperty(spinner, PropertyKey.OPAQUE, false);
}
@ -241,7 +243,6 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements SpinnerConstants {
JComponent editor = spinner.getEditor();
if (editorComponent != null) {
// System.out.println(((JComponent) editorComponent).getBorder());
editorComponent.setBackground(getBackground(c));
g.setColor(editorComponent.getBackground());
} else {
@ -282,6 +283,10 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements SpinnerConstants {
return c == null ? inactiveBackground : c.getBackground();
}
protected void updateBackground() {
PropertyUtil.installBackground(spinner, spinner.isEnabled() ? background : inactiveBackground);
}
protected Color getArrowBackground(final JComponent c) {
return c == null || !c.isEnabled() ? inactiveBackground : arrowBackground;
}

10
core/src/test/java/ui/spinner/SpinnerDemo.java

@ -38,9 +38,15 @@ public class SpinnerDemo implements ComponentDemo {
@Override
public JComponent createComponent() {
JSpinner spinner = new JSpinner();
DemoPanel panel = new DemoPanel(spinner);
JSpinner spinner = new JSpinner() {
@Override
public void updateUI() {
super.updateUI();
((JFormattedTextField) getEditor().getComponent(0)).setColumns(3);
}
};
DemoPanel panel = new DemoPanel(spinner);
JPanel controlPanel = panel.addControls(1);
controlPanel.add(new JCheckBox("enabled") {
{

Loading…
Cancel
Save