weblaf
weblaf copied to clipboard
Customizable values selector
There is one of most common implementations for single value selector in Swing - combobox. It allows simple selection from a popup list of values, but there are many possible cases when you might want to use something different from list - a tree, color chooser, table, checkbox list or any other custom value selection component for your specific cases.
There is also another major thing combobox doesn't support - multiselection. Combobox model allows you to have only one selected value at a time which limits combobox possible use cases a lot.
To summ up - Combobox does not allow deep customization of popup and its own model due to the way it is implemented in the JComboBox
and BasicComboBoxUI
which leads to only possible solution - separate component partially similar to JComboBox
which would allow such customization.
It is hard to say right now how exactly that component will function and look like as it requires some more investigation, but there are a few certain requirements:
- Model must not be tied to
ListModel
and should be capable of multiselection - Popup content should be fully customizeable on top of predefined interface
- Component should have style similar or even the same combobox has
Here are some references to possible implementations (visual-wise): https://harvesthq.github.io/chosen/ https://davidstutz.github.io/bootstrap-multiselect/ https://select2.github.io/examples.html
Possible component names:
WebSelector
WebExComboBox
WebValuesSelector
WebSelector
WebValuesChooser
WebChooser
WebComboChooser
WebPicker
What about WebMultiSelector
?
It could allow for a component to be added at the start of the dropdown, and a component to be added to the end, to make things like search boxes (as shown in the first example), or perhaps an option to add more options, or whatever else someone might want.
Or, for non-text selections, you could allow the user to supply a component to display, and when the user selects something, pass it to a user-supplied interface to provide what the MultiSelector should display - for example, you could use a table as your dropdown, and use a lambda that returns a WebLabel(s) with the text of the selected row(s), to the MultiSelector, which would display those. Same for trees - have a lambda that returns a WebLabel(s) with the text and icon of the selected node(s) to the MultiSelector. The program would be able to get the underlying JTable or JTree later, to get the actual selected data.
I don't really want to put "multi" part into the component name as it won't necessarily allow multiselection, it will all depend on the implementation. But WebSelector
doesn't sound bad, there could be some other options as well like WebComboChooser
or WebPicker
, will think about it once i get to it.
Regarding the box & popup implementation - base component will not dictate anything, it will all be given to the specific implementation, otherwise it won't be much different from default combobox. So yes, any custom tables, trees and whatever else accompanied by search fields, sort fields and whatnot will be possible within the popup. And custom view implementation will also be possible for the box.