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 08:21:42 UTC

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

neilcsmith-net commented on code in PR #3992:
URL: https://github.com/apache/netbeans/pull/3992#discussion_r908180412


##########
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:
   Niggle : please have brace on line above.



##########
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:
   My inclination is that this should only ever be InsetsUIResource.  Are there instances of plain Insets?  If so, from where, and should they be replaced?



-- 
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