您的位置:首页 > 其它

H3C-QOS配置记录

2011-09-06 10:21 417 查看
第五章

5.1 Swing列表

JList

创建代码:

String [] fruit={“apple”,”pear”,”orange”,”banana”}

JList myJList=new JList(fruit);

构造器:

JList()

JList(Object [] listData)

JList(ListModel dataModel)

JList(Vector listData)

常见方法:

getSelecttionForegroud()

setSelectionForeGroud(Color selectionForegroud)

getSelectionBackgroud()

setSelectionBackgroud(Color selectionBackgroud)

getModel()

setModel(ListModel model)

setListData(Object[] listData)

setListData(Vector listData)

setSelectionMode(int selectionMode)

getSelectionMode()

getMaxSelectionIndex()

getMinSelectionIndex()

isSelectedeIndex(int index)

isSelectionEmpty()

clearSelection()

getSelectedValues()

在NetBeans中使用

代码和运行图如下

private void jTextFieldCountryNameActionPerformed(java.awt.event.ActionEvent evt) {

// TODO 将在此处添加您的处理代码:

String countryName=this.jTextFieldCountryName.getText().trim();

if(countryName !=null &&! countryName.equals("")){

this.imageVector.add(countryName);

this.jLabelActionMessage.setText("你将"+countryName+"添加到列表中");

this.jListCountryList.setListData(this.imageVector);

}else{this.jLabelActionMessage.setText("请先输入内容再添加");

}

}

private void jButtonDeleteActionPerformed(java.awt.event.ActionEvent evt) {

// TODO 将在此处添加您的处理代码:

String countryName=(String)this.jListCountryList.getSelectedValue();

if(countryName !=null){

this.imageVector.remove(countryName);

this.jListCountryList.setListData(imageVector);

this.jLabelActionMessage.setText("你将"+countryName+"从列表中删除");

}else{

this.jLabelActionMessage.setText("请先选择一个选项");

}

}

private void jButtonAddActionPerformed(java.awt.event.ActionEvent evt) {

// TODO 将在此处添加您的处理代码:

String countryName=this.jTextFieldCountryName.getText().trim();

if(countryName !=null &&! countryName.equals("")){

this.imageVector.add(countryName);

this.jLabelActionMessage.setText("你将"+countryName+"添加到列表中");

this.jListCountryList.setListData(this.imageVector);

}else{

this.jLabelActionMessage.setText("请先输入内容再添加");

}

}

private void jListCountryListValueChanged(javax.swing.event.ListSelectionEvent evt) {

// TODO 将在此处添加您的处理代码:

String choosedCountry=(String)this.jListCountryList.getSelectedValue();

this.jLabelActionMessage.setText("你从列表中选择"+choosedCountry+"选项");

}

Swing组合框(JComboBox)
构造器:
JComboBox()
JComboBox(Object[] items)
JComboBox(Vector items)
JComboBox(ComboBoxModel model)

常用方法:
setModel(ComboBoxModel aModel)
getModel()
setSelectedItem(Object anObject)
getSelectedItem()
setSelectedIndex(int anIndex)
getSelectedIndex()
addItem(Object anObject)
removeItem(Object anObject)
removeItemAt(int anIndex)
removeAllItems()
showPopup()
hidePopup()
setPopupVisible(Boolean v)
isPopupVisible()
getItemCount()
getItemAt(int index)

在NetBeans中使用
代码和运行图如下
//先添加一个JComboBox,然后选择model属性,删除原来的项,添加新的项。
private void jComboBoxLoverItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO 将在此处添加您的处理代码:
String favor=(String)this.jComboBoxLover.getSelectedItem();
this.jLabel1.setText("你喜欢"+favor);

}
Swing组合框(JComboBox)

构造器:

JComboBox()

JComboBox(Object[] items)

JComboBox(Vector items)

JComboBox(ComboBoxModel model)

常用方法:

setModel(ComboBoxModel aModel)

getModel()

setSelectedItem(Object anObject)

getSelectedItem()

setSelectedIndex(int anIndex)

getSelectedIndex()

addItem(Object anObject)

removeItem(Object anObject)

removeItemAt(int anIndex)

removeAllItems()

showPopup()

hidePopup()

setPopupVisible(Boolean v)

isPopupVisible()

getItemCount()

getItemAt(int index)

在NetBeans中使用

代码和运行图如下

//先添加一个JComboBox,然后选择model属性,删除原来的项,添加新的项。

private void jComboBoxLoverItemStateChanged(java.awt.event.ItemEvent evt) {

// TODO 将在此处添加您的处理代码:

String favor=(String)this.jComboBoxLover.getSelectedItem();

this.jLabel1.setText("你喜欢"+favor);

}

Swing分割窗口(JSplitPane)

用于将一个窗口分割成两个部分。

构造器

JSplitPane()

JSplitPane(int newOrientation)

JSplitPane( int newOrientation,Boolean newContinuousLayout)

常用方法:

setDividerSize(int newSize)

getDividerSize()

setLeftComponent(Component comp)

Component getLeftComponent()

本文出自 “风停心止” 博客,请务必保留此出处http://wwssttt.blog.51cto.com/1289651/381814
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: