OSDN Git Service

ファイル選択コンボボックスでファイルパスが長い場合にリストの長さを大きくとるよう対応
authoryukihane <yukihane.feather@gmail.com>
Wed, 14 Sep 2011 06:04:31 +0000 (15:04 +0900)
committeryukihane <yukihane.feather@gmail.com>
Wed, 14 Sep 2011 06:04:31 +0000 (15:04 +0900)
frontend/src/yukihane/inqubus/gui/FileComboBox.java

index 9df1168..993acd8 100644 (file)
@@ -1,15 +1,18 @@
 package yukihane.inqubus.gui;
 
+import java.awt.Dimension;
 import javax.swing.JComboBox;
 import javax.swing.JTextField;
 
 /**
- *
+ * ComboBoxの幅に入りきらない場合はリストを拡張します.
+ * http://www.jroller.com/santhosh/entry/make_jcombobox_popup_wide_enough
  * @author yuki
  */
 class FileComboBox extends JComboBox<String> {
 
     private static final long serialVersionUID = 1L;
+    private boolean layingOut = false;
 
     FileComboBox() {
         super();
@@ -19,4 +22,23 @@ class FileComboBox extends JComboBox<String> {
     JTextField getEditorComponent() {
         return (JTextField) getEditor().getEditorComponent();
     }
+
+    @Override
+    public void doLayout() {
+        try {
+            layingOut = true;
+            super.doLayout();
+        } finally {
+            layingOut = false;
+        }
+    }
+
+    @Override
+    public Dimension getSize() {
+        Dimension dim = super.getSize();
+        if (!layingOut) {
+            dim.width = Math.max(dim.width, getPreferredSize().width);
+        }
+        return dim;
+    }
 }