简体   繁体   English

快速搜索java swing应用程序?

[英]Fast search in java swing applications?

I'm wandering myself what component is the best for displaying fast search results in swing. 我在自己徘徊什么组件最适合在秋千中显示快速搜索结果。 I want to create something like this, make a text field where user can enter some text, during his entering I'll improve in back end fast search on database, and I want to show data bellow the text box, and he will be able to browse the results and on pres enter result will be displayed in table. 我想创建这样的东西,创建一个文本字段,用户可以在其中输入一些文本,在他进入期间我将改进后端快速搜索数据库,我想在文本框下面显示数据,他将能够浏览结果和输入结果将显示在表格中。 So my question is is there any component which already have this logic for displaying? 所以我的问题是有没有任何组件已经有这个逻辑显示? Or is it's not, what is the best way to implement that. 或者不是,实现它的最佳方式是什么。

This search will be something what ajax gives me on web, same logic same look and feel, if it's possible on desktop application. 这个搜索将是ajax在网络上给我的东西,相同的逻辑相同的外观和感觉,如果它可以在桌面应用程序上。

Are you looking for something like an AutoComplete component for Java Swing? 您是否在寻找类似Java Swing的AutoComplete组件?

SwingX has such a component. SwingX有这样一个组件。 See here for the JavaDoc. 请参阅此处获取JavaDoc。 It has a lot of utility methods to do various things, ie auto-completing a text box from the contents of a JList. 它有很多实用方法可以做各种事情,即从JList的内容中自动完成一个文本框。

You will have to first attach a listener to the JTextField s Document to be notified whenever the user types in the field (or changes it). 您必须首先将监听器附加到JTextFieldDocument ,以便在用户键入字段(或更改它)时收到通知。

From there, you can fire off any server-side code you need. 从那里,您可以启动所需的任何服务器端代码。 The results of that can be used to update a listbox. 其结果可用于更新列表框。

A few things to keep in mind: 要记住以下几点:

  1. The code to do the search against the backend must be in another thread 对后端进行搜索的代码必须在另一个线程中
  2. The code that updates the list box should update the list box's model 更新列表框的代码应更新列表框的模型
  3. You will need to manage all your backend search results so that you only update the listbox with the most recent result (eg user types 'A', backenf searches for that. Meanwhile, user has typed 'C', kicking off a backend search for 'AC'. You need to ensure the results from the 'A' search dont' make it to the listbox if the 'AC' search results are available). 您将需要管理所有后端搜索结果,以便您只更新具有最新结果的列表框(例如,用户类型'A',backenf搜索它。同时,用户键入'C',开始后端搜索'AC'。如果“AC”搜索结果可用,您需要确保“A”搜索的结果“不要”进入列表框。

我强烈建议您查看Glazed Lists - 这是一个更精细的开源Java库,它使您所要求的大部分内容非常容易。

Use Hibernate Search. 使用Hibernate Search。

The SwingHack ( http://oreilly.com/catalog/9780596009076/ ) book has an example of this. SwingHack( http://oreilly.com/catalog/9780596009076/ )这本书有一个例子。

In the interest of killing two birds with one stone: have a separate indexing thread. 为了一石二鸟:有一个单独的索引线。 This will: 这将:

  1. Improve the speed of searches whenever they are executed. 无论何时执行,都可以提高搜索速度。
  2. Improve the responsiveness of the UI since indexing is happening in a separate thread. 由于索引在单独的线程中发生,因此提高了UI的响应能力。

Of course, exactly how you perform the indexing will vary widely depending on your particular application. 当然,你究竟是如何进行索引会根据您的具体应用有很大的不同。 Here is a good place to start researching: Search Indexing . 这是一个开始研究的好地方: 搜索索引 And please, ignore the reference to Web 3.0 [sic]. 请忽略对Web 3.0 [sic]的引用。

It is possible of course. 当然可以。 It is simple too. 这也很简单。 For drop down list of terms just use popup menu. 对于下拉列表,只需使用弹出菜单。 This is simple. 这很简单。 The background processing of entered text is simple too. 输入文本的后台处理也很简单。 Enjoy! 请享用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM