TextField tf = new TextField(); JFXAutoComplete autoCompleter = new JFXAutoComplete(tf);
autoCompleter.addToDictionary("hapiness"); autoCompleter.addToDictionary("hello"); autoCompleter.addToDictionary("heritage"); autoCompleter.addToDictionary("cruel world"); autoCompleter.addToDictionary("war"); autoCompleter.addToDictionary("wording"); autoCompleter.addToDictionary("world");For example, with this dictionary, the following Popup will be presented after typing the "h" key:
setCaseSensitive(boolean)
: true if case is sensitive for the searchsearchHitsFromStart(boolean)
: true if the Search for hits is performed from the start of the typed text only. For example the dictionary word "conf" would be a hit for the text "unconfirmed" if this property was set to false, and false if it was set to true. There would be a hit in the two cases for the text "confirmed"showPopup(boolean)
: true if a Popup Window presenting the possible hits should be presented. if false, the first hit will be automatically used for the completionacceptDuplicates(boolean)
: true if the dictionary accept duplicatesstartSearchOnKeyCode(KeyCode)
: the KeyCode to use to start the search. By default the search is started immediately during the typing. If the KeyCode is not null, the search will be started by typing this KeyCode with the Control key downsearchPerWord(boolean)
: true if the Search is performed per each wordsetResultsLimit(int)
: allows to limit the number of results per category (-1 means no limitation)TextField tf = new TextField(); JFXAutoComplete autoCompleter = new JFXAutoComplete(tf); tf.addEventHandler(AutoCompleteEvent.AUTOCOMPLETE, new EventHandler<AutoCompleteEvent>() { @Override public void handle(AutoCompleteEvent event) { System.out.println(event.getText() + " => " + event.getStartOffset()); } });To listen to the selection of the optional additional search item:
TextField tf = new TextField(); JFXAutoComplete autoCompleter = new JFXAutoComplete(tf); tf.addEventHandler(AdditionalSearchEvent.FULLTEXTSEARCH, new EventHandler<AdditionalSearchEvent>() { @Override public void handle(AdditionalSearchEvent event) { System.out.println(event.getText()); } });
autoCompleter.addCategory("category 1"); autoCompleter.addCategory("category 2"); autoCompleter.addToDictionary("category 1", "hello"); autoCompleter.addToDictionary("category 1", "heritage"); autoCompleter.addToDictionary("category 1", "happiness"); autoCompleter.addToDictionary("category 1", "woodbye"); autoCompleter.addToDictionary("category 2", "cruel world"); autoCompleter.addToDictionary("category 2", "war"); autoCompleter.addToDictionary("category 2", "will"); autoCompleter.addToDictionary("category 2", "world"); autoCompleter.addToDictionary("category 2", "wall");The following Popup will be presented after typing the "w" key:
autoComplete-list
styleClassautoComplete-category
styleClassautoComplete-hit
styleClass if categories are not used, and autoComplete-hit-category
if categories are used.autoComplete-category { -fx-font-style: italic; -fx-underline: true; }Here we show the categories in italic and underlined:
autoCompleter.addCategory("category 1"); autoCompleter.addCategory("category 2"); autoCompleter.addToDictionary("category 1", "hello"); autoCompleter.addToDictionary("category 1", "heritage"); autoCompleter.addToDictionary("category 1", "happiness"); autoCompleter.addToDictionary("category 1", "woodbye"); autoCompleter.addToDictionary("category 2", "cruel world"); autoCompleter.addToDictionary("category 2", "war"); autoCompleter.addToDictionary("category 2", "will"); autoCompleter.addToDictionary("category 2", "world"); autoCompleter.addToDictionary("category 2", "wall");The following Popup will be presented after typing the "w" key:
TextField tf = new TextField(); JFXAutoComplete autoCompleter = new JFXAutoComplete(tf); autoCompleter.searchHitsFromStart(false); //add the dictionary autoCompleter.addToDictionary("hello"); autoCompleter.addToDictionary("highlight"); autoCompleter.addToDictionary("cruel world"); autoCompleter.addToDictionary("war"); autoCompleter.addToDictionary("wording"); autoCompleter.addToDictionary("world");
Copyright 2006-2024 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences