我们如何在JavaSwing中添加类似Google的搜索框?
我在Combobox中尝试了一些带有动态列表的代码,但在键入后,它并没有在Combobox中的选定项上添加整个单词我们如何在JavaSwing中添加类似Google的搜索框?,java,swing,Java,Swing,我在Combobox中尝试了一些带有动态列表的代码,但在键入后,它并没有在Combobox中的选定项上添加整个单词 如何使其更像谷歌搜索框那样动态?您可以使用此代码使用数据库连接动态更新Combobox //code: String pattern=TabletCombobox.getSelectedItem().toString(); System.out.println(pattern); //TabletCombobox.setSelectedItem(pat
如何使其更像谷歌搜索框那样动态?您可以使用此代码使用数据库连接动态更新Combobox
//code:
String pattern=TabletCombobox.getSelectedItem().toString();
System.out.println(pattern);
//TabletCombobox.setSelectedItem(pattern);
//AutoCompleteDecorator decorator;
//AutoCompleteDecorator.decorate(TabletCombobox);
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(url,username,password);
Statement st=con.createStatement();
String Query="select * from tablet";
ResultSet rs=st.executeQuery(Query);
int i=1;
while(rs.next())
{
TabletCombobox.add(this, rs.getString(1),i++);
}
}
catch(Exception e)
{
System.err.println(e);
}
yaa是正确的,但它不会搜索我们在可编辑组合框中键入的内容,所以要做什么?您希望自动完成。有一些实现,Swing实验室,SwingX库,请参考[此链接][1]。这就是你的疑问[1]: