(转)
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 阅读(553) 
评论(0)  编辑  收藏  所属分类: 
Swing