Java Dropdown Checklist - java

I understand how to make a multiple-select list box using JLists but I want to add JCheckBoxes to the list and make it dropdown like. The best visual representation I have found online is dropdown-check-list.
What would be the best way to accomplish the above?
I was thinking of a TableList. Any suggestions?

If you are using JList, then its as simple as changing the ListCellRenderer to return a JCheckbox component.
EDIT:
For JCombobox, you can use combobox.setRenderer(myListRenderer);

This code snippet may help you.
The basic idea is to handle actionPerformed or mouseClick events by yourself and keep states of the corresponding items (checked/unchecked) in your own data structure. You'll be able to use that data structure for rendering checkboxes in a dropdown

Related

Can't add to List

I have a List box in my UI design, however, I can't access the .getElement() method that many people seem to be accessing when implementing a get method.
Is there any reason for this and is there a way to add values to this list box?
I have a List box in my UI design,
I assume you mean JList when using Swing. "List" is an AWT component. Be specific when you ask a question to avoid confusion.
Is there any reason for this and is there a way to add values to this list box?
You add items to the DefaultListModel, not the JList.
Read the section from the Swing tutorial on How to Use Lists for more information and working examples.

Alternative for JComboBox without drop down list

Java, Swing, JCombobox.
I need a single-line textbox with 2 arrows (up and down) instead of drop down list.
I'm sure that's pretty easy but i've not been succeeded to find solution.
Thanks in advance.
For your requirement, Java Swing already has a component called JSpinner.
have look at JSpinner with SpinnerListModel
Try using a
JList. Just set the height of the list so that only one element is visible at a time. For further infomation please refer to this...
http://zetcode.com/tutorials/javaswingtutorial/basicswingcomponentsII/

Wicket, how to lazy-load DropDown choices on click?

I have a lot of DropDownChoice components with many items in a form, and on loading the form, I'd like to display only the saved selected options. When the user clicks on a DropDownChoice, I'd like to ajax-load the full item list on the fly.
Can this be done?
Add a OnChangeAjaxBehavior to your dropdown-component. Override the onUpdate-method and add another component to the target. The chosen value of the dropdown-component is inside its model.
Update: Okey, I think I know what you're trying to achieve. Add an AjaxFormComponentUpdatingBehavior to your dropdown component with "onclick" as constructor parameter.
Override the onUpdate-method and add your dropdown component to the target. Before you do that, update the dropdown model, so that it now contains all values.
If you have a lot of options to show then using <select> is not the best option.
Better check http://ivaynberg.github.com/select2/ or http://livedocs.dojotoolkit.org/dijit/form/FilteringSelect or any other JS based component which can load options on demand via Ajax.
Maybe you could go with the AjaxEditableLabels... Using the AjaxEditableChoiceLabel from Wicket Extensions, you'll get a compponent that displays the current value as a Label until clicked and the changes to a DropDownChoice via Ajax. That should be pretty much like the solution you're looking for.

Java: How to update custom ListCellRenderer?

I implemented my own ListCellRenderer for my chat app. I use a JList to list all users. The cell renderer consists mainly of an icon that displays if a particular user is currently on- or offline and his/her name. The list is controlled by a DefaultListModel which I use to provide the JList with the necessary information.
But when the list model does change its state (e.g. a user goes offline), the list cell renderer seems not to be invoked?
Somebody any idea how to solve this problem? Tried to call updateUI() on the JList instance, but did not helped.
Many thanks in advance!
The cell renderer probably works fine. What is not working is the ListModel. The DefaultListModel does not detect changes to the internal state of the model objects. You need to call fireContentsChanged on the list model. Probably you need to add listeners to your model objects and maybe you even have to extend the DefaultListModel; as I don't see the code of it I don't know how yours look.
You should not just call a random method with a name that sounds good (updateUI does something very different).

How to make an expandable list with Java Swing

I need to make an expandable list using java swing. I will attempt to demonstrate:
Unexpanded:
>[Expand me!]
>[And me!]
Expanded:
|[Expand me!]
>[Expand us too!]
>[Expand us too!]
>[Expand us too!]
>[And me!]
So, when you click on the "Expand me" portion of the list, another lists will drop down, possibly containing more expandable lists. If you were to click on it again, it's "sub-lists" would then retract. Pretty basic. And, as you can see, I am not looking for JComboBox, and I do not think JList can do this. If someone were to point me in the right direction, or give some programming examples, I would be grateful.
Thanks,
MirroredFate
How about using a JTree.
A control that displays a set of hierarchical data as an outline.
You can try using a JTable and put a button in the first column. When the button is clicked you add more data in the rows in between.
update
Something like this:
Or this
I think the first uses a JTree but that the idea.
BTW these two belong to JIDE Soft, check if it is feasible for you to buy a license:
http://www.jidesoft.com/products/grids.htm
Is not trivial to roll you own but is not impossible either.
check for TreeTable or one example or Outline, but with notice, that on official Java (SnOracle) pages any progress died ...,

Categories

Resources