swing中如何获取到可编辑的下拉列表的值,要获得编辑后输入的值,如何得到?
展开全部
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TestXun extends JFrame implements ActionListener{
private String[] str = {"111","222","333","444"};
private JComboBox jcb = new JComboBox(str);
private JLabel jl = new JLabel("此处显示选择内容");
public TestXun(){
this.intialFrame();
}
public void intialFrame(){
Toolkit toolkit = this.getToolkit();
Dimension dimension = toolkit.getScreenSize();
int width = dimension.width;
int height = dimension.height;
this.setLayout(null);
this.setBounds(width/2-300, height/2-300, 600, 600);
jcb.setBounds(250,250,50,30);
jcb.addActionListener(this);
this.add(jcb);
jl.setBounds(100, 400, 200, 30);
this.add(jl);
this.setVisible(true);
}
public static void main(String args[]){
TestXun tx = new TestXun();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String str_jcb =(String)jcb.getSelectedItem();
this.jl.setText(str_jcb);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询