Browse Source

Fixed painting issue with spinner.

Fixed spinner button layout when used as cell editor.
pull/127/head
weisj 5 years ago
parent
commit
af6e592d90
  1. 2
      core/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerBorder.java
  2. 27
      core/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerUI.java

2
core/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerBorder.java

@ -79,7 +79,7 @@ public class DarkSpinnerBorder implements Border, UIResource {
: editor.getBounds().x - 1 - borderSize; : editor.getBounds().x - 1 - borderSize;
g.setColor(getBorderColor(spinner)); g.setColor(getBorderColor(spinner));
if (!treeCellEditor) { if (!treeCellEditor) {
g.fillRect(off, size, 1, height - 2 * size); g.fillRect(off, size - 1, 1, height - 2 * size + 1);
} else { } else {
g.fillRect(off, 0, 1, height); g.fillRect(off, 0, 1, height);
} }

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

@ -91,6 +91,7 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements PropertyChangeListe
private JComponent editor; private JComponent editor;
private JButton prevButton; private JButton prevButton;
private Component editorComponent; private Component editorComponent;
private JButton nextButton;
public static ComponentUI createUI(final JComponent c) { public static ComponentUI createUI(final JComponent c) {
@ -135,9 +136,21 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements PropertyChangeListe
} }
} }
protected void adjustButton(final JComponent button, final int adj) {
Rectangle bounds = button.getBounds();
bounds.x += adj;
button.setBounds(bounds);
}
@Override @Override
public void layoutContainer(final Container parent) { public void layoutContainer(final Container parent) {
super.layoutContainer(parent); super.layoutContainer(parent);
if (isTableCellEditor(spinner) || isTreeCellEditor(spinner)) {
int adj = borderSize / 2;
if (!spinner.getComponentOrientation().isLeftToRight()) adj *= -1;
adjustButton(prevButton, adj);
adjustButton(nextButton, adj);
}
if (editor != null && !spinner.getComponentOrientation().isLeftToRight()) { if (editor != null && !spinner.getComponentOrientation().isLeftToRight()) {
Rectangle bounds = editor.getBounds(); Rectangle bounds = editor.getBounds();
bounds.x += borderSize; bounds.x += borderSize;
@ -160,7 +173,7 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements PropertyChangeListe
@Override @Override
protected Component createNextButton() { protected Component createNextButton() {
JButton nextButton = createArrow(SwingConstants.NORTH); nextButton = createArrow(SwingConstants.NORTH);
nextButton.setName("Spinner.nextButton"); nextButton.setName("Spinner.nextButton");
nextButton.setBorder(new EmptyBorder(1, 1, 1, 1)); nextButton.setBorder(new EmptyBorder(1, 1, 1, 1));
nextButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); nextButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
@ -273,6 +286,7 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements PropertyChangeListe
&& Boolean.TRUE.equals(((JComponent) c).getClientProperty(KEY_IS_TREE_EDITOR)); && Boolean.TRUE.equals(((JComponent) c).getClientProperty(KEY_IS_TREE_EDITOR));
} }
@Override @Override
protected void installDefaults() { protected void installDefaults() {
super.installDefaults(); super.installDefaults();
@ -301,8 +315,9 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements PropertyChangeListe
boolean leftToRight = spinner.getComponentOrientation().isLeftToRight(); boolean leftToRight = spinner.getComponentOrientation().isLeftToRight();
int off = leftToRight ? bounds.x : bounds.x + bounds.width; int off = leftToRight ? bounds.x : bounds.x + bounds.width;
Area rect; Area rect;
if (!isTableCellEditor(spinner)) { if (!isTableCellEditor(spinner) && !isTreeCellEditor(spinner)) {
rect = new Area(new RoundRectangle2D.Double(bSize - 1, bSize - 1, width - 2 * bSize + 2, height - 2 * bSize + 1, rect = new Area(new RoundRectangle2D.Double(bSize - 1, bSize - 1, width - 2 * bSize + 1,
height - 2 * bSize + 1,
arc, arc)); arc, arc));
} else { } else {
rect = new Area(new Rectangle(0, 0, width, height)); rect = new Area(new Rectangle(0, 0, width, height));
@ -341,16 +356,16 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements PropertyChangeListe
text.setHorizontalAlignment(alignment); text.setHorizontalAlignment(alignment);
} }
} }
spinner.repaint(); spinner.revalidate();
} else if (KEY_EDITOR_ALIGNMENT.equals(key) && isTableCellEditor(spinner)) { } else if (KEY_EDITOR_ALIGNMENT.equals(key) && isTableCellEditor(spinner)) {
if (editorComponent instanceof JTextField && evt.getNewValue() instanceof Integer) { if (editorComponent instanceof JTextField && evt.getNewValue() instanceof Integer) {
((JTextField) editorComponent).setHorizontalAlignment((Integer) evt.getNewValue()); ((JTextField) editorComponent).setHorizontalAlignment((Integer) evt.getNewValue());
} }
spinner.repaint(); spinner.revalidate();
} else if (KEY_VARIANT.equals(key)) { } else if (KEY_VARIANT.equals(key)) {
spinner.repaint(); spinner.repaint();
} else if (KEY_IS_TREE_EDITOR.equals(key)) { } else if (KEY_IS_TREE_EDITOR.equals(key)) {
spinner.repaint(); spinner.revalidate();
} }
} }

Loading…
Cancel
Save