org.jdesktop.swingx.autocomplete

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Swing Library » swingx » org.jdesktop.swingx.autocomplete 
org.jdesktop.swingx.autocomplete
Contains classes to enable automatic completion for JComboBox and other components.

The automatic completion feature allows the user to enter a few characters using the keyboard - meanwhile, the computer "guesses" what the user intents to enter. Take a look at the example below to get an idea of the resulting user experience. Suppose the user types 'J','O','R' and 'G'...

The easiest way to get automatic completion for a component is to use the {@link org.jdesktop.swingx.autocomplete.AutoCompleteDecorator AutoCompleteDecorator}.

Enabling automatic completion for e.g. a JComboBox is only one line of code:

import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;
[...]
JComboBox comboBox = [...];
AutoCompleteDecorator.decorate(comboBox);

When the combo box is not editable when calling {@link org.jdesktop.swingx.autocomplete.AutoCompleteDecorator#decorate(JComboBox) decorate}, the automatic completion will be strict (only allowing items contained in the combo box). When the combo box is editable it will also be possible to enter items that are not contained in the combo box.

Take care when enabling automatic completion for a JComboBox that is used as the cell editor for a JTable. You need to use the special {@link org.jdesktop.swingx.autocomplete.ComboBoxCellEditor ComboBoxCellEditor} instead of the standard DefaultCellEditor:

JTable table = [...];
JComboBox comboBox = [...];
[...]
TableColumn column = table.getColumnModel().getColumn([...]);
column.setCellEditor(new ComboBoxCellEditor(comboBox));

If you want to enable automatic completion for a component that is not supported by the {@link org.jdesktop.swingx.autocomplete.AutoCompleteDecorator AutoCompleteDecorator}, you need to implement {@link org.jdesktop.swingx.autocomplete.AbstractAutoCompleteAdaptor AbstractAutoCompleteAdaptor}. For an example see {@link org.jdesktop.swingx.autocomplete.ComboBoxAdaptor ComboBoxAdaptor} and {@link org.jdesktop.swingx.autocomplete.ListAdaptor ListAdaptor}.

The automatic completion works only for subclasses of {@link javax.swing.text.JTextComponent JTextComponent}. So you either use a component that contains a JTextComponent (e.g. JComboBox) or you connect a JTextComponent with another component (e.g. a JTextField and a JList). Of course, it's also possible to enable automatic completion for a JTextComponent without another visual component.

Once you have a custom implementation of {@link org.jdesktop.swingx.autocomplete.AbstractAutoCompleteAdaptor AbstractAutoCompleteAdaptor}, you normally would only have to make three more calls:

AbstractAutoCompleteAdaptor adaptor = new YourAdaptor([...]);
AutoCompleteDocument document = new AutoCompleteDocument(adaptor, true); // or false if you need non-strict matching
AutoCompleteDecorator.decorate(yourTextComponent, document, adaptor);

Java Source File NameTypeComment
AbstractAutoCompleteAdaptor.javaClass This is the interface that binds the mechanism for automatic completion to a data model, a selection model (e.g.
AutoCompleteComboBoxEditor.javaClass

Wrapper around the combobox editor that translates combobox items into strings.

AutoCompleteDecorator.javaClass This class contains only static utility methods that can be used to set up automatic completion for some Swing components.
AutoCompleteDocument.javaClass A document that can be plugged into any JTextComponent to enable automatic completion.
AutoCompleteDocumentTest.javaClass
ComboBoxAdaptor.javaClass An implementation of the AbstractAutoCompleteAdaptor that is suitable for JComboBox.
ComboBoxCellEditor.javaClass

This is a cell editor that can be used when a combo box (that has been set up for automatic completion) is to be used in a JTable.

ListAdaptor.javaClass An implementation of the AbstractAutoCompleteAdaptor that is suitable for a JList in conjunction with a JTextComponent.
ObjectToStringConverter.javaClass

This class is used to provide string representations for objects when doing automatic completion.

A class inherited from this class could be used, when the object's toString method is not appropriate for automatic completion.

An example for i18n:

 public class I18NStringConverter extends ObjectToStringConverter {
 ResourceBundle bundle;
 public I18NStringConverter(ResourceBundle bundle) {
 this.bundle = bundle;
 }
 public String getPreferredStringForItem(Object item) {
 return item==null ? null : bundle.getString(item.toString());
 }
 }
 

It's also possible to return more than one string representation.

TextComponentAdaptor.javaClass An implementation of the AbstractAutoCompleteAdaptor that is suitable for a JTextComponent.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.