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

问题描述 投票:-3回答:1
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 <string>)未定义”

the constructor jcombobox(string) is undefined

java jcombobox
1个回答
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);

}

© www.soinside.com 2019 - 2024. All rights reserved.