You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2022/06/28 14:07:42 UTC

[GitHub] [netbeans] eirikbakke commented on a diff in pull request #3992: Improve vertical centering of FlatLAF buttons on Windows

eirikbakke commented on code in PR #3992:
URL: https://github.com/apache/netbeans/pull/3992#discussion_r908528858


##########
platform/o.n.swing.laf.flatlaf/src/org/netbeans/swing/laf/flatlaf/FlatLFCustoms.java:
##########
@@ -120,6 +129,34 @@ public Object[] createApplicationSpecificKeysAndValues() {
             "Table.ancestorInputMap.RightToLeft", new LazyModifyInputMap( "Table.ancestorInputMap.RightToLeft", removeCtrlPageUpDownKeyBindings ), // NOI18N
             "Tree.focusInputMap", new LazyModifyInputMap( "Tree.focusInputMap", removeCtrlPageUpDownKeyBindings ), // NOI18N
         };
+        List<Object> result = new ArrayList<>();
+        result.addAll(Arrays.asList(constants));
+        if (Utilities.isWindows()) {
+          /* Make sure button labels appear vertically centered on Windows. On the standard
+          Windows LAF, WindowsButtonUI/WindowsRadioButtonUI/WindowsToggleButtonUI.getPreferredSize
+          add one pixel to the button's height to ensure that it is odd-numbered. This makes the
+          text centered with either Tahoma 11 (the default Swing Windows LAF font) or Segoe UI 12
+          (the default font on modern Windows versions, and on FlatLAF on Windows). */
+          for (String key : new String[] { "Button", "RadioButton", "ToggleButton" }) {
+            UIDefaults defaults = UIManager.getDefaults();
+            Font font = defaults.getFont(key + ".font");
+            Insets bm = defaults.getInsets(key + ".margin");
+            if (font != null && bm != null &&
+                font.getFamily().equals("Segoe UI") && font.getSize() == 12)
+            {
+              if (bm.top == bm.bottom) {
+                result.add(key + ".margin");
+                /* Create an InsetsUIResource rather than an Insets instance if necessary, as
+                FlatLAF treats them differently. Not doing this caused buttons in the main toolbar
+                to become very wide. */
+                result.add(bm instanceof InsetsUIResource

Review Comment:
   It was just a precaution, not something I observed. But since FlatLAF treats Insets and InsetsUIResource differently, I'd imagine cases where FlatLAF customizations might pick one or the other (though this would be very weird). I figured that leaving the same kind of instance was the least likely to cause problems.



##########
platform/o.n.swing.laf.flatlaf/src/org/netbeans/swing/laf/flatlaf/FlatLFCustoms.java:
##########
@@ -120,6 +129,34 @@ public Object[] createApplicationSpecificKeysAndValues() {
             "Table.ancestorInputMap.RightToLeft", new LazyModifyInputMap( "Table.ancestorInputMap.RightToLeft", removeCtrlPageUpDownKeyBindings ), // NOI18N
             "Tree.focusInputMap", new LazyModifyInputMap( "Tree.focusInputMap", removeCtrlPageUpDownKeyBindings ), // NOI18N
         };
+        List<Object> result = new ArrayList<>();
+        result.addAll(Arrays.asList(constants));
+        if (Utilities.isWindows()) {
+          /* Make sure button labels appear vertically centered on Windows. On the standard
+          Windows LAF, WindowsButtonUI/WindowsRadioButtonUI/WindowsToggleButtonUI.getPreferredSize
+          add one pixel to the button's height to ensure that it is odd-numbered. This makes the
+          text centered with either Tahoma 11 (the default Swing Windows LAF font) or Segoe UI 12
+          (the default font on modern Windows versions, and on FlatLAF on Windows). */
+          for (String key : new String[] { "Button", "RadioButton", "ToggleButton" }) {
+            UIDefaults defaults = UIManager.getDefaults();
+            Font font = defaults.getFont(key + ".font");
+            Insets bm = defaults.getInsets(key + ".margin");
+            if (font != null && bm != null &&
+                font.getFamily().equals("Segoe UI") && font.getSize() == 12)
+            {

Review Comment:
   Will fix.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists