swing中如何获取到可编辑的下拉列表的值,要获得编辑后输入的值,如何得到?
Stringstr[]={"ddd","222","1111","3333"};JComboBoxaa=newJComboBox(str);Stringaa=change...
String str[] = { "ddd", "222", "1111", "3333" };
JComboBox aa= new JComboBox(str);
String aa = change.getSelectedItem().toString();
为什么用这种方法获取不到输入的值 展开
JComboBox aa= new JComboBox(str);
String aa = change.getSelectedItem().toString();
为什么用这种方法获取不到输入的值 展开
展开全部
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);
}
}
追问
jComboBox.setEditable(true);让下拉框是可编辑状态,我现在是要可编辑的下拉列表,在可编辑状态下,输入编辑的值,获取输入后的值,如何获取输入的值呢?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询