标签:
1.文本域组件
public class TestJTextArea {
public static void main(String[] args) {
JFrame jf=new JFrame("演示文本域");
JPanel jp=new JPanel();
JTextArea jta=new JTextArea("演示文本域,演示文本域,演示文本域",6,6);
jta.setLineWrap(true);
jp.add(jta);
jf.add(jp);
jf.setSize(200,200);
jf.setLocation(200,200);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
}
}
2.列表框
public class TestJTextArea {
public static void main(String[] args) {
JFrame jf=new JFrame("演示文本域");
JPanel jp=new JPanel();
JTextArea jta=new JTextArea("演示文本域,演示文本域,演示文本域",6,6);
jta.setLineWrap(true);
jp.add(jta);
jf.add(jp);
jf.setSize(200,200);
jf.setLocation(200,200);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
}
}
3.下拉列表框
import java.awt.FlowLayout;
import javax.swing.AbstractListModel;
import javax.swing.ComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class TestJComboBox extends AbstractListModel<String> implements ComboBoxModel<String>{
String selectedItem=null;
String[] listData={"现金支付","银行卡支付","支付宝支付"};
public String getElementAt(int index){
return listData[index];
}
public int getSize(){
return listData.length;
}
public Object getSelectedItem(){
return selectedItem;
}
public void setSelectedItem(Object arg0){
selectedItem=(String)arg0;
}
public int getIndex(){
for(int i=0;i<listData.length;i++){
if(listData[i].equals(getSelectedItem()))
return i;
}
return 0;
}
public static void main(String[] args) {
JFrame jf=new JFrame("演示下拉列表框");
jf.setSize(300,200);
jf.setLocation(200,200);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
jf.setLayout(new FlowLayout());
JLabel j1=new JLabel("请选择支付方式:");
jf.add(j1);
JComboBox<String>jcb=new JComboBox<>(new TestJComboBox());
jf.add(jcb);
}
}
标签:
原文地址:http://www.cnblogs.com/daochong/p/4824604.html