diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java index 639c2777..f186641c 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java @@ -40,6 +40,7 @@ import com.github.weisj.darklaf.listener.MouseMovementListener; import com.github.weisj.darklaf.listener.PopupMenuAdapter; import com.github.weisj.darklaf.ui.text.bridge.DarkTextFieldUIBridge; import com.github.weisj.darklaf.util.DarkUIUtil; +import com.github.weisj.darklaf.util.FontUtil; import com.github.weisj.darklaf.util.PropertyUtil; /** @author Jannis Weis */ @@ -142,11 +143,9 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh Rectangle rect = super.getVisibleEditorRect(); 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.y = ins.top + FontUtil.getCenteredFontPosition(height, fm); rect.height = fm.getHeight(); } adjustTextRect(getComponent(), rect); diff --git a/utils/src/main/java/com/github/weisj/darklaf/util/FontUtil.java b/utils/src/main/java/com/github/weisj/darklaf/util/FontUtil.java index 98ffa3c6..af045dfb 100644 --- a/utils/src/main/java/com/github/weisj/darklaf/util/FontUtil.java +++ b/utils/src/main/java/com/github/weisj/darklaf/util/FontUtil.java @@ -23,8 +23,10 @@ package com.github.weisj.darklaf.util; import java.awt.*; +import javax.swing.*; import javax.swing.text.StyleContext; + public class FontUtil { public static Font createFont(final String family, final int style, final int size) { @@ -33,6 +35,13 @@ public class FontUtil { return new NonUIResourceFont(StyleContext.getDefaultStyleContext().getFont(family, style, size)); } + public static int getCenteredFontPosition(final int height, final FontMetrics fm) { + int asc = fm.getMaxAscent(); + int y = (height - asc) / 2; + y -= fm.getDescent() / 2; + return y; + } + public static class NonUIResourceFont extends Font { public NonUIResourceFont(final Font font) {