JComboBox — 콤보박스 컴포넌트
JComboBox — 콤보박스 컴포넌트
JComboBox는 버튼이나 편집 가능한 필드와 드롭다운 목록을 결합한 컴포넌트입니다. 사용자는 목록에서 값을 선택하거나 직접 입력할 수 있습니다.
본문
public class JComboBox<E> extends JComponent implements ItemSelectable, ListDataListener, ActionListener, Accessible
버튼이나 편집 가능한 필드와 드롭다운 목록을 결합한 컴포넌트입니다. 사용자는 요청 시 나타나는 드롭다운 목록에서 값을 선택할 수 있습니다. 콤보박스를 편집 가능하게 만들면 사용자가 값을 입력할 수 있는 편집 가능한 필드가 포함됩니다. 경고: Swing은 스레드에 안전하지 않습니다. 이 클래스의 직렬화된 객체는 향후 Swing 버전과 호환되지 않을 수 있습니다. 현재 직렬화 지원은 단기 저장이나 같은 버전의 Swing을 실행하는 애플리케이션 간 RMI에 적합합니다. 1.4부터 모든 JavaBean의 장기 저장 지원이 java.beans 패키지에 추가되었으니 XMLEncoder를 참고하세요. 자세한 내용은 The Java Tutorial의 "How to Use Combo Boxes"를 참고하세요.
JComboBox
public JComboBox()
기본 데이터 모델로 JComboBox를 만듭니다.
JComboBox
public JComboBox(ComboBoxModel<E> aModel)
기존 모델의 항목으로 JComboBox를 만듭니다.
- 매개변수:
aModel- 콤보박스 항목을 제공하는ComboBoxModel
JComboBox
public JComboBox(E[] items)
배열의 항목으로 JComboBox를 만듭니다.
- 매개변수:
items- 콤보박스에 삽입할 항목 배열
JComboBox
public JComboBox(Vector<E> items)
Vector의 항목으로 JComboBox를 만듭니다.
- 매개변수:
items- 콤보박스에 삽입할 항목 Vector
setModel
@BeanProperty(description="The model that represents the list or contents of the combo box.") public void setModel(ComboBoxModel<E> aModel)
콤보박스 데이터 모델을 설정합니다.
- 매개변수:
aModel- 콤보박스의 목록을 나타내는ComboBoxModel
getModel
public ComboBoxModel<E> getModel()
현재 데이터 모델을 반환합니다.
- 반환값: 현재
ComboBoxModel
setSelectedItem
public void setSelectedItem(Object anObject)
콤보박스의 표시 영역에 있는 선택 항목을 anObject로 설정합니다.
- 매개변수:
anObject- 선택할 목록 항목
getSelectedItem
public Object getSelectedItem()
현재 선택된 항목을 반환합니다.
- 반환값: 현재 선택된 항목
setSelectedIndex
public void setSelectedIndex(int anIndex)
인덱스 anIndex에 있는 항목을 선택합니다.
- 매개변수:
anIndex- 선택할 항목의 인덱스
getSelectedIndex
public int getSelectedIndex()
선택된 항목의 인덱스를 반환합니다.
- 반환값: 현재 선택된 항목의 인덱스, 선택된 항목이 없으면 -1
getItemCount
public int getItemCount()
목록의 항목 수를 반환합니다.
- 반환값: 목록의 항목 수
getItemAt
public E getItemAt(int index)
인덱스 index에 있는 항목을 반환합니다.
- 매개변수:
index- 목록의 인덱스 - 반환값: 인덱스 index에 있는 항목
addItem
public void addItem(E item)
목록에 항목을 추가합니다.
- 매개변수:
item- 목록에 추가할 항목
insertItemAt
public void insertItemAt(E item, int index)
지정된 인덱스에 항목을 삽입합니다.
- 매개변수:
item- 삽입할 항목 - 매개변수:
index- 항목을 삽입할 인덱스
removeItem
public void removeItem(Object anObject)
목록에서 항목을 제거합니다.
- 매개변수:
anObject- 제거할 항목
removeAllItems
public void removeAllItems()
목록에서 모든 항목을 제거합니다.
setEditable
@BeanProperty(description="If true, the user can type a value.") public void setEditable(boolean aFlag)
콤보박스를 편집 가능하게 만듭니다.
- 매개변수:
aFlag- 콤보박스를 편집 가능하게 하려면 true
isEditable
public boolean isEditable()
콤보박스가 편집 가능한지 여부를 반환합니다.
- 반환값: 콤보박스가 편집 가능하면 true
setRenderer
@BeanProperty(hidden=true, visualUpdate=true, description="The renderer that paints the item selected in the list.") public void setRenderer(ListCellRenderer<? super E> aRenderer)
렌더러를 설정합니다. 콤보박스가 편집 불가능하면 이 렌더러가 선택된 항목을 그리거나 모든 항목을 그리는 데 사용됩니다.
- 매개변수:
aRenderer- 사용할ListCellRenderer
getRenderer
public ListCellRenderer<? super E> getRenderer()
현재 렌더러를 반환합니다.
- 반환값: 현재
ListCellRenderer
setMaximumRowCount
@BeanProperty(description="The maximum number of rows the popup should have.") public void setMaximumRowCount(int count)
팝업 창에 표시되는 최대 행 수를 설정합니다.
- 매개변수:
count- 표시할 최대 행 수
getMaximumRowCount
public int getMaximumRowCount()
팝업 창에 표시할 최대 행 수를 반환합니다.
- 반환값: 최대 행 수
addActionListener
public void addActionListener(ActionListener l)
ActionListener를 추가합니다. 이 리스너는 사용자가 선택한 항목을 선택할 때마다 호출됩니다.
- 매개변수:
l- 추가할ActionListener