我试图从数据库中读取一些值并将其显示在List中。
list = new List();
list.setSize(30, 280);
try {
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager
.getConnection("jdbc:mysql://localhost:3306/project?"
+ "user=root&password=virus");
statement = connect.createStatement();
preparedStatement = connect
.prepareStatement("select subname from subject");
rs=preparedStatement.executeQuery();
while (rs.next()) {
subject = rs.getString("subname");
list.add(subject);
}
}
List的import语句是 -
import java.awt.List;
所以我认为Java控件在JavaFX中不可用。
我试图将列表放在HBox中 -
hb.getChildren().addAll(addSubName, list, b2);
然后我收到了错误 -
method addAll in interface ObservableList<E> cannot be applied to given types;
required: Node[]
found: TextField,List,Button
reason: varargs mismatch; List cannot be converted to Node
where E is a type-variable:
E extends Object declared in interface ObservableList
此错误是否可纠正?如果没有,请告诉我一个可以用作JavaFX中List的替代的控件。