Browse Source

Fixed text shifting when making comboBox editable.

Signed-off-by: weisj <weisj@arcor.de>
pull/60/head
weisj 5 years ago
parent
commit
5182603f7a
  1. 6
      core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonBorder.java
  2. 41
      core/src/main/java/com/github/weisj/darklaf/ui/combobox/DarkComboBoxUI.java
  3. 3
      core/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerBorder.java
  4. 4
      core/src/main/resources/com/github/weisj/darklaf/properties/ui/comboBox.properties
  5. 2
      core/src/main/resources/com/github/weisj/darklaf/properties/ui/spinner.properties

6
core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonBorder.java

@ -173,8 +173,10 @@ public class DarkButtonBorder implements Border, UIResource {
}
int shadow = DarkButtonUI.isShadowVariant(c) ? 0 : getShadowSize();
boolean square = DarkButtonUI.isSquare(c);
Insets pad = isThin(c) ? square ? squareThinInsets : thinInsets
: square ? squareInsets : insets;
Insets pad = isThin(c) ? square ? squareThinInsets
: thinInsets
: square ? squareInsets
: insets;
return new InsetsUIResource(pad.top, pad.left, pad.bottom + shadow, pad.right);
}

41
core/src/main/java/com/github/weisj/darklaf/ui/combobox/DarkComboBoxUI.java

@ -208,12 +208,12 @@ public class DarkComboBoxUI extends BasicComboBoxUI implements Border, PropertyC
protected static boolean isTableCellEditor(final Component c) {
return c instanceof JComponent
&& Boolean.TRUE.equals(((JComponent) c).getClientProperty("JComboBox.isTableCellEditor"));
&& Boolean.TRUE.equals(((JComponent) c).getClientProperty("JComboBox.isTableCellEditor"));
}
protected static boolean isTreeCellEditor(final Component c) {
return c instanceof JComponent
&& Boolean.TRUE.equals(((JComponent) c).getClientProperty("JComboBox.isTreeCellEditor"));
&& Boolean.TRUE.equals(((JComponent) c).getClientProperty("JComboBox.isTreeCellEditor"));
}
private Color getForeground() {
@ -237,7 +237,7 @@ public class DarkComboBoxUI extends BasicComboBoxUI implements Border, PropertyC
int buttonWidth = squareButton
? buttonHeight
: arrowButton.getPreferredSize().width
+ arrowButton.getInsets().left + arrowButton.getInsets().right;
+ arrowButton.getInsets().left + arrowButton.getInsets().right;
//adjust the size based on the button width
size.height += insets.top + insets.bottom;
size.width += insets.left + insets.right + buttonWidth;
@ -251,27 +251,18 @@ public class DarkComboBoxUI extends BasicComboBoxUI implements Border, PropertyC
@Override
protected Rectangle rectangleForCurrentValue() {
Rectangle rect = super.rectangleForCurrentValue();
if (comboBox.isEditable() && !comboBox.getComponentOrientation().isLeftToRight()) {
rect.x += borderSize;
rect.width -= borderSize;
if (comboBox.isEditable()) {
if (comboBox.getComponentOrientation().isLeftToRight()) {
rect.x += boxPadding.left;
rect.width -= boxPadding.left;
} else {
rect.width -= borderSize + 1;
rect.x += 1;
}
}
return rect;
}
@Override
protected Insets getInsets() {
if (isTableCellEditor(comboBox)) {
return new InsetsUIResource(cellPadding.top, cellPadding.left, cellPadding.bottom, cellPadding.right);
}
if (comboBox.getComponentOrientation().isLeftToRight()) {
return new InsetsUIResource(borderSize + boxPadding.top, borderSize + boxPadding.left,
borderSize + boxPadding.bottom, borderSize);
} else {
return new InsetsUIResource(borderSize + boxPadding.top, borderSize,
borderSize + boxPadding.bottom, borderSize + boxPadding.right);
}
}
public void paintCurrentValue(final Graphics g, final Rectangle bounds, final boolean hasFocus) {
ListCellRenderer<Object> renderer = comboBox.getRenderer();
Component c = renderer.getListCellRendererComponent(listBox, comboBox.getSelectedItem(),
@ -293,9 +284,6 @@ public class DarkComboBoxUI extends BasicComboBoxUI implements Border, PropertyC
boolean shouldValidate = c instanceof JPanel;
Rectangle r = new Rectangle(bounds);
if (isTableCellEditor(comboBox)) {
r.x--;
}
currentValuePane.paintComponent(g, c, comboBox, r.x, r.y, r.width, r.height, shouldValidate);
// return opaque for combobox popup items painting
if (changeOpaque) {
@ -406,7 +394,11 @@ public class DarkComboBoxUI extends BasicComboBoxUI implements Border, PropertyC
if (isTableCellEditor(c) || isTreeCellEditor(c)) {
return new InsetsUIResource(cellPadding.top, cellPadding.left, cellPadding.bottom, cellPadding.right);
}
return new InsetsUIResource(borderSize, borderSize, borderSize, borderSize);
if (comboBox.getComponentOrientation().isLeftToRight()) {
return new InsetsUIResource(boxPadding.top, boxPadding.left, boxPadding.bottom, borderSize);
} else {
return new InsetsUIResource(boxPadding.top, borderSize, boxPadding.bottom, boxPadding.right);
}
}
@Override
@ -424,6 +416,7 @@ public class DarkComboBoxUI extends BasicComboBoxUI implements Border, PropertyC
if ("componentOrientation".equals(key)) {
comboBox.doLayout();
comboBox.repaint();
comboBox.getEditor().getEditorComponent().setComponentOrientation(comboBox.getComponentOrientation());
} else if ("editable".equals(key)) {
comboBox.repaint();
} else if ("JComboBox.isTableCellEditor".equals(key) || "JComboBox.isTreeCellEditor".equals(key)) {

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

@ -121,8 +121,7 @@ public class DarkSpinnerBorder implements Border, UIResource {
if (DarkSpinnerUI.isTableCellEditor(c) || DarkSpinnerUI.isTreeCellEditor(c)) {
return new InsetsUIResource(cellInsets.top, cellInsets.left, cellInsets.bottom, cellInsets.right);
}
return new InsetsUIResource(insets.top + borderSize, insets.left + borderSize,
insets.bottom + borderSize, insets.right + borderSize);
return new InsetsUIResource(insets.top, insets.left, insets.bottom, insets.right);
}
@Override

4
core/src/main/resources/com/github/weisj/darklaf/properties/ui/comboBox.properties

@ -39,8 +39,8 @@ ComboBox.selectionBackground = %highlightFillFocus
ComboBox.arc = %arc
ComboBox.borderThickness = %borderThickness
ComboBox.selectionForeground = %textSelectionForeground
ComboBox.insets = 2,2,2,2
ComboBox.cellEditorInsets = 2,1,2,1
ComboBox.insets = 5,5,5,5
ComboBox.cellEditorInsets = 1,1,1,1
ComboBox.buttonPad = 4
#Icons

2
core/src/main/resources/com/github/weisj/darklaf/properties/ui/spinner.properties

@ -39,7 +39,7 @@ Spinner.arc = %arc
Spinner.borderThickness = %borderThickness
Spinner.cellEditorInsets = 2,5,2,5
Spinner.insets = 2,2,2,2
Spinner.insets = 5,5,5,5
Spinner.buttonPad = 4
Spinner.plus.icon = misc/plus.svg[themed]

Loading…
Cancel
Save