posts - 38,  comments - 22,  trackbacks - 0

          (轉)
          package comboBox;

          import java.awt.Dimension;
          import java.util.Vector;

          import javax.swing.ComboBoxModel;
          import javax.swing.JComboBox;
          import javax.swing.JFrame;

          public class WideComboBox extends JComboBox {

           public WideComboBox() {
           }

           public WideComboBox(final Object items[]) {
            super(items);
           }

           public WideComboBox(Vector items) {
            super(items);
           }

           public WideComboBox(ComboBoxModel aModel) {
            super(aModel);
           }

           private boolean layingOut = false;

           public void doLayout() {
            try {
             layingOut = true;
             super.doLayout();
            } finally {
             layingOut = false;
            }
           }

           public Dimension getSize() {
            Dimension dim = super.getSize();
            if (!layingOut)
             dim.width = Math.max(dim.width, getPreferredSize().width);
            return dim;
           }

           public static void main(String[] args) {
            JFrame jf = new JFrame();
            WideComboBox wc = new WideComboBox(new String[] { "11111111111111",
              "22222222222222", "333" });
            jf.getContentPane().add(wc);
            jf.setVisible(true);
           }
          }

          posted on 2007-04-11 14:08 aaabbb 閱讀(543) 評論(0)  編輯  收藏 所屬分類: Swing
          主站蜘蛛池模板: 定结县| 汝阳县| 隆昌县| 托克托县| 阿图什市| 吴忠市| 婺源县| 庆阳市| 汽车| 永吉县| 闽侯县| 沈丘县| 孟连| 甘谷县| 海口市| 石首市| 孟州市| 兴化市| 仙游县| 平舆县| 普洱| 崇州市| 祁门县| 南京市| 安龙县| 荔浦县| 交口县| 淅川县| 观塘区| 中牟县| 吴堡县| 辛集市| 上林县| 连南| 饶平县| 从江县| 华亭县| 宕昌县| 铁岭市| 南开区| 长白|