为什么我在创建JComboBox对象时遇到此编译错误?

时间:2022-09-06 12:13:52
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);
}

I get the following compilation error "the constructor JComboBox(ArrayList<string>) is undefined"

我得到以下编译错误“构造函数JComboBox(ArrayList )未定义”

为什么我在创建JComboBox对象时遇到此编译错误?

1 个解决方案

#1


0  

You are almost there!! JCombobox takes arguments as String Array. You will have to convert it or add it manually

你快到了! 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);

}

}

#1


0  

You are almost there!! JCombobox takes arguments as String Array. You will have to convert it or add it manually

你快到了! 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);

}

}