为什么在创建JComboBox对象时会出现此编译错误?

时间:2017-12-27 09:14:56

标签: java jcombobox

Connection con =DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root","password");
System.out.println("Connected database successfully...");
PreparedStatement ps = con.prepareStatement( "select * from web");          
ResultSet rs = ps.executeQuery();                   
ArrayList<String> v = new ArrayList<>();
while ( rs.next()) {
String s = rs.getString(1);                               
v.add(s);     
} 
bx = new JComboBox(v);
bx.setBounds(150, 20, 200, 20);
f.add(bx);
}

我得到以下编译错误“构造函数JComboBox(ArrayList&lt; string&gt;)未定义

the constructor jcombobox(string) is undefined

1 个答案:

答案 0 :(得分:0)

你快到了! JCombobox将参数作为String Array。您必须转换它或手动添加它

Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root","password");
System.out.println("Connected database successfully...");
PreparedStatement ps = con.prepareStatement( "select * from web");          

ResultSet rs = ps.executeQuery();                   
bx = new JComboBox();
while ( rs.next()) 
{
    String s = rs.getString(1);                               
    bx.addItem(s);    
} 


bx.setBounds(150, 20, 200, 20);
f.add(bx);

}