Open NiranjanShah opened 6 years ago
The code you posted is kind of a mess, with code and comments intertwined, but as far as I can see, you have created a class called AutoCompleteTextfield and want to add that to a form. You only have a noargs constructor in your class, so you could have do instantiate it and then do the binding manually:
val tf = AutoCompleteTextField()
add(tf)
tf.textProperty().bind(yourProperty)
Hello, We would like to use the attached AutoCompleteTextField in the form. Kindly guide how to use it
PS: We are new in tornadofx, so possibly we would be using wrong way, kindly guide class AutoCompleteTextField : TextField() { /* The existing autocomplete entries. / /**
@return The existing autocomplete entries. */ val entries: SortedSet
/* The popup used to select an entry. /
private val entriesPopup: ContextMenu
/* Construct a new AutoCompleteTextField. / init { entries = TreeSet() entriesPopup = ContextMenu() textProperty().addListener { observableValue, s, s2 -> if (text.length == 0) { entriesPopup.hide() } else { val searchResult = LinkedList()
searchResult.addAll(entries.subSet(text, text + Character.MAX_VALUE))
if (entries.size > 0) {
populatePopup(searchResult)
if (!entriesPopup.isShowing) {
entriesPopup.show(this@AutoCompleteTextField, Side.BOTTOM, 0.0, 0.0)
}
} else {
entriesPopup.hide()
}
}
}
}
/**
@param searchResult The set of matching strings. */ private fun populatePopup(searchResult: List) {
val menuItems = LinkedList()
// If you'd like more entries, modify this line.
val maxEntries = 10
val count = Math.min(searchResult.size, maxEntries)
for (i in 0 until count) {
val result = searchResult[i]
val entryLabel = Label(result)
val item = CustomMenuItem(entryLabel, true)
item.onAction = EventHandler {
text = result
entriesPopup.hide()
}
menuItems.add(item)
}
entriesPopup.items.clear()
entriesPopup.items.addAll(menuItems)
}
When use in the form, it says too many arguments for public constructor init { with(root) { form { fieldset("Edit person") { field("Name") { AutoCompleteTextField { etName = this