Here you can find the source of createEditableComboBox(String strActionCommand, ActionListener alListener, int iPreferredWidth)
Parameter | Description |
---|---|
strActionCommand | - action command name |
alListener | - action listener |
iPreferredWidth | - max width size |
public static JComboBox<?> createEditableComboBox(String strActionCommand, ActionListener alListener, int iPreferredWidth)
//package com.java2s; import java.awt.Dimension; import java.awt.event.ActionListener; import javax.swing.JComboBox; public class Main { public static JComboBox<?> createEditableComboBox(String strActionCommand, ActionListener alListener, int iPreferredWidth) { JComboBox<?> cbResult = new JComboBox<Object>(); //set preffered width if (iPreferredWidth != 0) { cbResult.setPreferredSize(new Dimension(iPreferredWidth, cbResult.getPreferredSize().height)); }/* w w w .j a va2 s .co m*/ //set action command if (strActionCommand != null && !strActionCommand.isEmpty()) { cbResult.setActionCommand(strActionCommand); } //check editable flag cbResult.setEditable(true); //add action listener if (alListener != null) { cbResult.addActionListener(alListener); } return cbResult; } }