【问题标题】:How Can we add a Google like Search box in java Swing? [duplicate]我们如何在 java Swing 中添加类似 Google 的搜索框? [复制]
【发布时间】:2015-10-03 06:21:52
【问题描述】:

我在Combobox 中尝试了一些带有动态列表的代码,但是在键入后它不会在组合框中的选定项目上添加整个单词。

我怎样才能让它像 Google 搜索框一样更加动态?

【问题讨论】:

标签: java swing


【解决方案1】:

您可以使用此代码使用数据库连接动态更新组合框.....

    //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);
    }

【讨论】:

  • 没错,但是它不会搜索我们在可编辑组合框中输入的内容,所以该怎么办??
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-29
  • 2014-12-20
  • 1970-01-01
  • 1970-01-01
  • 2019-12-28
  • 2016-12-05
相关资源
最近更新 更多