判断 jcombobox 是否选中 的方法
1个回答
展开全部
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JComboBox;
import javax.swing.JFrame;
public class Myjcombobox extends JFrame {
private JComboBox com;
private String[] str = new String[] { "Item1", "Item2" };
public Myjcombobox() {
init();
}
private void init() {
// TODO Auto-generated method stub
com = new JComboBox(str);
add(com);
com.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent arg0) {
// TODO Auto-generated method stub
// 打印选择项
System.out.println(com.getSelectedItem());
}
});
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Myjcombobox mian = new Myjcombobox();
mian.setVisible(true);
mian.setSize(200, 50);
}
}
import java.awt.event.ItemListener;
import javax.swing.JComboBox;
import javax.swing.JFrame;
public class Myjcombobox extends JFrame {
private JComboBox com;
private String[] str = new String[] { "Item1", "Item2" };
public Myjcombobox() {
init();
}
private void init() {
// TODO Auto-generated method stub
com = new JComboBox(str);
add(com);
com.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent arg0) {
// TODO Auto-generated method stub
// 打印选择项
System.out.println(com.getSelectedItem());
}
});
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Myjcombobox mian = new Myjcombobox();
mian.setVisible(true);
mian.setSize(200, 50);
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询