center FixedSizeButton vertically and improve comment for magic number (-2)
authorSergey Simonchik <sergey.simonchik@jetbrains.com>
Wed, 8 Jun 2016 20:06:01 +0000 (23:06 +0300)
committerSergey Simonchik <sergey.simonchik@jetbrains.com>
Wed, 8 Jun 2016 20:06:01 +0000 (23:06 +0300)
platform/platform-api/src/com/intellij/openapi/ui/ComponentWithBrowseButton.java
platform/platform-api/src/com/intellij/openapi/ui/FixedSizeButton.java

index bc245120e8837d9d71049e3f4d0be3e838b2f512..931c43d2dca8390e1173de3e85203243e7ca8201 100644 (file)
@@ -34,7 +34,6 @@ import com.intellij.openapi.vfs.LocalFileSystem;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.ui.GuiUtils;
 import com.intellij.ui.UIBundle;
-import com.intellij.util.Consumer;
 import com.intellij.util.ui.UIUtil;
 import com.intellij.util.ui.accessibility.ScreenReader;
 import com.intellij.util.ui.update.LazyUiDisposable;
@@ -68,8 +67,7 @@ public class ComponentWithBrowseButton<Comp extends JComponent> extends JPanel i
     if (browseActionListener != null) {
       myBrowseButton.addActionListener(browseActionListener);
     }
-    // don't force FixedSizeButton to occupy the whole height
-    add(wrapWithoutResize(myBrowseButton), BorderLayout.EAST);
+    add(centerComponentVertically(myBrowseButton), BorderLayout.EAST);
 
     myBrowseButton.setToolTipText(UIBundle.message("component.with.browse.button.browse.button.tooltip.text"));
     // FixedSizeButton isn't focusable but it should be selectable via keyboard.
@@ -82,9 +80,10 @@ public class ComponentWithBrowseButton<Comp extends JComponent> extends JPanel i
     }
   }
 
-  private static JPanel wrapWithoutResize(JComponent component) {
-    JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
-    panel.add(component);
+  @NotNull
+  private static JPanel centerComponentVertically(@NotNull Component component) {
+    JPanel panel = new JPanel(new GridBagLayout());
+    panel.add(component, new GridBagConstraints());
     return panel;
   }
 
index be947ccc607eba7adefc3097edfbf7a062e1c89b..036e574263ea524d0c7b8c60098de930f096777e 100644 (file)
@@ -89,7 +89,10 @@ public class FixedSizeButton extends JButton {
     if (myComponent != null) {
       int size = myComponent.getPreferredSize().height;
       if (myComponent instanceof JComboBox && (UIUtil.isUnderIntelliJLaF() || UIUtil.isUnderDarcula())) {
-        size -= 2; // decrement to match JTextField's preferred height
+        // JComboBox's preferred height is 2px greater than JTextField's one, because
+        // javax.swing.DefaultListCellRenderer#getNoFocusBorder returns (1,1,1,1) border.
+        // Decrement to have equal sizes for pretty look when stacked vertically
+        size -= 2;
       }
       return new Dimension(size, size);
     }