How to show the maximum number of data into swt combobox? - java

My SWT Combo has a lot of items and the dropdownlist always shows more data at the same time in linux platform based on display size. (yes I can scroll up and down to see all the other items)
I want the dropdown list to show items at the same time e.g. 10 items at the same time.
I used this code:
m_comboBoxViewer.getCCombo().setVisibleItemCount(10);
I am getting this exception:
org.eclipse.core.runtime.AssertionFailedException: null argument:
at org.eclipse.core.runtime.Assert.isNotNull(Assert.java:85)
at org.eclipse.core.runtime.Assert.isNotNull(Assert.java:73)
at org.eclipse.jface.viewers.ComboViewer.getCCombo(ComboViewer.java:182)
How can I make the dropdown list, to show limited items at the same time? Has anyone an example?

It looks like you are using a ComboViewer which is using a Combo control. You must use a CCombo control to be able to set the visible items count.
CCombo comboBox = new CCombo(parent, ... style flags ....);
m_comboBoxViewer = new ComboViewer(comboBox);

Related

Set combobox items dynamically based on search query

I have a combobox that I would like to act as a search field. When I enter some value I want to call a backend service that would based on the entered value return a list of possible values. I would like to set these values as the combobox items dynamically. So far I have this code:
ComboBox<String> comboBox = new ComboBox<>("Name");
comboBox.setAllowCustomValue(true);
comboBox.setAutofocus(true);
comboBox.addCustomValueSetListener(e -> comboBox.setItems(backendService.getData(e.getValue())));
This works, but it is not ideal, as I (the user) has to type the value, hit enter and focus the combobox again. At this point the matched values from backend are set as items in the combobox. Is there a way to fetch items from the backend dynamically as the user writes in the input with some time delay (e.g. ValueChangeMode.LAZY for TextField) and set them as combobox items while writing user input?
After reading through this link I found a solution using lazy data loading. I had to adjust my backend service to accept a PageRequest object, so the following line of code did exactly what I wanted:
comboBox.setItems(query ->
backendService.getData(PageRequest.of(query.getPage(), query.getPageSize())));

Finding an element on a combobox which has too many data on JavaFx

I have a combobox that has around 90 elements in it. In some applications when you select the combobox you can type and find the element easily. But when i tried it on javaFx it didn't work.Is there a way to do this? Because now user needs to scroll down which sucks due to number of elements in the combobox.
You can take a look at this https://github.com/jesuino/javafx-combox-autocomplete
or JavaFX - Filtered ComboBox
If not what you can have as a work around is have a text box that is bound to the observable of data in the combobox and on keypress you filter the observable

how to disable a list element in swt list eclipse

Is it possible to disable only certain elements of a swt list display.I want a list display with a certain clickable strings and a few disabled strings based on my conditions.Is it possible to this?
It is not possible with SWT List widget. you might need to come up with your own widget( may be Table with one Column)
If you really want it then add a selection listener that would detect if the selection is on the "disabled" item and then adjust up/down/clear selection depending on the list contents.
You may also use table with a single column - then you should be able to custom-draw disabled items (e.g. to use lighter font or a different background).

Filtering a ListView in wicket using 2 drop down boxes

I am trying to filter a list that is placed into a listview through the use of 2 drop down boxes.
The first dropdown box is titled price and the second is owner.
I want to be able to select a value in one or more of these drop down boxes and then have the List view re-render with the filtered results.
The trouble is I do not know how to begin this task, would someone be so kind as to enlighten me :D
Thanks in advance!
Your best starting point is probably this example: (Source code also available on this page, ChoicePage.java is the name)
First of all, you have to use a dynamic model in your ListView that generates the list of items depending on what you had selected in the dropdown boxes.
Then the basic idea is that you add an AjaxFormComponentUpdatingBehavior to the components that control the updates (your two dropdown boxes in your case), and in the onUpdate() method of this behaviour you should add the component you want to update to that AjaxRequestTarget passed.

wrapping the contents of List in SWT

I have created fixed size List. If the list has one item which is bigger than the List size it self, then the item should be wrapped to multiple lines.
SWT.WRAP can't be used as it supports only Label and Text controls.
For item customization of List you need to create your own widget.
Check e.g. http://www.snip2code.com/Snippet/11489/Custom-SWT-List-Box
In this way you will have full control on the rendering of the different items
If you want to have multiple lines in labels per item in a list, then you use a table instead. See the SWT snippet "draw multiple lines in a table item" for the relevant code.
The bad news is that all items must have the same height...

Categories