Browse Source

Fix overwriting null border for BorderlessTextField.

Adjust editor rect height when recalculating font specific baseline position for textfields.
Ignore font specific baseline when doing mouse position checks.
Adjust combobox editor rect to not move when toggling editing mode on rtl combobox.
pull/187/head
weisj 5 years ago
parent
commit
29f9f7a8b6
  1. 5
      core/src/main/java/com/github/weisj/darklaf/ui/combobox/DarkComboBoxUI.java
  2. 9
      core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java
  3. 20
      core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextUI.java
  4. 2
      core/src/test/java/ui/text/TextFieldDemo.java

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

@ -320,11 +320,12 @@ public class DarkComboBoxUI extends BasicComboBoxUI implements ComboBoxConstants
protected Rectangle rectangleForCurrentValue() {
Rectangle rect = super.rectangleForCurrentValue();
if (comboBox.isEditable()) {
if (comboBox.getComponentOrientation().isLeftToRight()) {
boolean ltr = comboBox.getComponentOrientation().isLeftToRight();
if (ltr) {
rect.x += boxPadding.left;
rect.width -= boxPadding.left;
} else {
rect.width -= boxPadding.right - borderSize;
rect.width -= boxPadding.right - borderSize + 1;
}
}
return rect;

9
core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java

@ -142,14 +142,19 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh
@Override
protected Rectangle getVisibleEditorRect() {
return getVisibleEditorRect(true);
}
protected Rectangle getVisibleEditorRect(final boolean shrinkHeight) {
Rectangle rect = super.getVisibleEditorRect();
if (rect != null) {
if (rect != null && shrinkHeight) {
FontMetrics fm = SwingUtilities2.getFontMetrics(editor, editor.getFont());
int asc = fm.getMaxAscent();
Insets ins = editor.getInsets();
int height = editor.getHeight() - ins.top - ins.bottom;
rect.y = ins.top + (height - asc) / 2;
rect.y -= fm.getDescent() / 2;
rect.height = fm.getHeight();
adjustTextRect(getComponent(), rect);
}
return rect;
@ -180,7 +185,7 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh
if (oldClear != clearHovered) {
editor.repaint();
}
Rectangle textRect = getVisibleEditorRect();
Rectangle textRect = getVisibleEditorRect(false);
if (textRect.contains(p)) {
getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
} else {

20
core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextUI.java

@ -107,13 +107,6 @@ public abstract class DarkTextUI extends BasicTextUI implements PropertyChangeLi
@Override
protected void installDefaults() {
super.installDefaults();
// OpenJDK BorderlessTextField has a bug with its setBorder implementation
// so we reset the border
// See https://mail.openjdk.java.net/pipermail/swing-dev/2020-March/010226.html
if (editor != null && "javax.swing.plaf.basic.BasicComboBoxEditor$BorderlessTextField".equals(editor.getClass()
.getName())) {
editor.setBorder(null);
}
if (editor != null) {
PropertyUtil.installProperty(editor, ToolTipConstants.KEY_STYLE, ToolTipStyle.PLAIN);
PropertyUtil.installBooleanProperty(editor, KEY_ROUNDED_SELECTION, "TextComponent.roundedSelection");
@ -127,6 +120,12 @@ public abstract class DarkTextUI extends BasicTextUI implements PropertyChangeLi
installPopupMenu();
}
public static boolean isBorderlessTextField(final JTextComponent textComponent) {
if (textComponent == null) return false;
String className = textComponent.getClass().getName();
return "javax.swing.plaf.basic.BasicComboBoxEditor$BorderlessTextField".equals(className);
}
protected void installPopupMenu() {
JPopupMenu popupMenu = editor.getComponentPopupMenu();
if (popupMenu == null || popupMenu instanceof UIResource) {
@ -146,6 +145,13 @@ public abstract class DarkTextUI extends BasicTextUI implements PropertyChangeLi
}
protected void installBorder() {
if (isBorderlessTextField(editor)) {
// OpenJDK BorderlessTextField has a bug with its setBorder implementation
// so we reset the border
// See https://mail.openjdk.java.net/pipermail/swing-dev/2020-March/010226.html
if (editor.getBorder() != null) editor.setBorder(null);
return;
}
if (uninstalling) return;
MarginBorderWrapper.installBorder(editor);
}

2
core/src/test/java/ui/text/TextFieldDemo.java

@ -46,7 +46,7 @@ public class TextFieldDemo implements ComponentDemo {
public JComponent createComponent() {
JTextField textField = createTextField();
textField.putClientProperty(DarkTextUI.KEY_DEFAULT_TEXT, "Default Text");
textField.setFont(new Font("Roboto", Font.PLAIN, 13));
// textField.setFont(new Font("Roboto", Font.PLAIN, 13));
DemoPanel panel = new DemoPanel(textField);
JPanel controlPanel = panel.addControls();

Loading…
Cancel
Save