Vaadin ComboBox invisible when readonly - combobox

Why does a Vaadin ComboBox get invisible when doing setReadOnly(true)?
Screenshots
normal
invisible
The source code
import java.util.List;
import com.vaadin.ui.ComboBox;
public class PropertyComboBox extends ComboBox
{
public PropertyComboBox(List<String> properties)
{
super();
for(String property: properties) {this.addItem(property);}
this.setImmediate(true);
this.setMultiSelect(false);
this.setNewItemsAllowed(false);
this.setInputPrompt("Property");
this.setReadOnly(true);
}
}

If you are trying to create a combo box in which the user can't write anything, check out the NativeSelect component.
From the API doc:
This is a simple drop-down select without, for instance, support for multiselect, new items, lazyloading, and other advanced features. Sometimes "native" select without all the bells-and-whistles of the ComboBox is a better choice.
If you don't need these features, then you should definetely consider using NativeSelect.

All components get "invisible" when you set them to read only. I couldn't find any reason for that and was wondering too.
My suggestion (a bit hacky): disable the components and change their disabled appearence within CSS.

Nexus is right, component become invisible when set to readOnly. In fact setting to read-only add the "v-readonly" css classname and the CSS do the rest.
Regards.

Related

Reference retrieval of a ButtonGroup instance

I have created an instance of ButtonGroup and associated that to two RadioButtons. The RadioButtons are added to a Container and the Container added to a Form screen. When the "Back" button is pressed, I want to clear the ButtonGroup selection and reset certain variable instances.
I want to place the code in the ActionListener I have made for the "Back" function. My question is how to retrieve the reference of the ButtonGroup in order to clearSelection()?
Generally we recommend recreating the Form instead of caching it if you intend to "reset it" so I'd avoid this.
If you still want to go in this direction check out getButtonGroup() in RadioButton. You can also set a new group with the setter method.
You can use setUnselectAllowed(true) then invoke setSelected(false) on both buttons. Then restore default selection behavior using setUnselectAllowed(false).
While looking at animateLayout() method of ComponentSelector for another issue that I had, I realized that I may use this Class to obtain Component object references jQuery style elegantly. Very powerful and useful concept for codename one.
should adding or removing components trigger a repaint?

How can I add a badge to a tab in CodenameOne?

I tried this code:
FloatingActionButton badge = FloatingActionButton.createBadge("33");
badge.bindFabToContainer(tabs.getTabComponentAt(3), Component.RIGHT, Component.TOP);
However for some reason I get a
java.lang.IllegalArgumentException: Component is already contained in Container
exception.
I tried also:
tabs.getTabsContainer().getComponentAt(3)
without success.
Bind creates a new container that should be added instead of the component. This won't work for a case like tabs where the button be added when you add a tab component. You are also relying on internal behavior of looking up a specific tab which is pretty fragile to begin with.
You can use the approach listed here which shows how you can create a completely custom component to represent a tab.

Sencha Architect: extend Ext.form.field.Picker

In Sencha Architect I want to extend the Ext.form.field.Picker to create a custom component. But the Ext.form.field.Picker is not in the available toolbox elements. Can I do it somehow?
I try to override the trigger field, and change the:
extend: 'Ext.form.field.Trigger'
to
extend: 'Ext.form.field.Picker'
but it does nothing.
In your Sencha Architect (preferably version 3.1) click on the plus sign (top right corner) inside the Project Inspector, select Class and View.
You will get a new empty class being extended from Ext.Base. Change the extend property to Ext.form.field.Picker and you should get a popup asking "Would you like to transform this Class to a Ext.form.field.Picker, to enable full configuration and behavior". Click yes and you should be good to go.

ExtJS4: from which class to derive?

I'm working on custom component, which will contain combo and displayfield. It's supposed to be a combobox with validation message next to it.
I'm wondering, from which base class to derive that one in order to have such functionality like store binding ect?
Why don't you use standard ExtJs validation mechanism? It will produce exact outcome you want - a label next to the combobox.
Eventually I found that it can be a simple Ext.panel.Panel.

Combobox clearing value issue

I've stumbled on an issue with Comboboxes in javafx2.2. This is the scenario:
Users click on the 'editFile' button.
Another pane becomes visible (with the setVisible method).
This pane contains 6 comboboxes.
Three of them have fixed items: cboReport, cboSales, cboSend. Three of them get their data from a db (ObservableList) and get populated when the pane becomes visible: cboFile, cboCustomer, cboVet
The user selects a file number from the cboFile. The rest of the comboboxes are beeing set with the correct values.
The user presses the save button, the file gets saved as intended.
Next the user presses a close button.
When the window closes, the data on the pane gets resetted through a resetGUI_editFilePane() method. There is have lines like:
...
cboReport.getSelectionModel().clearSelection();
cboSales.getSelectionModel().clearSelection();
cboSend.getSelectionModel().clearSelection();
cboFile.getSelectionModel().clearSelection();
cboCustomer.getSelectionModel().clearSelection();
cboVet.getSelectionModel().clearSelection();
cboFile.getItems().clear();
cboCustomer.getItems().clear();
cboVet.getItems.clear();
...
When the user opens the pane again by pressing the 'editFile' button I notice that only the 'fixed item' comboboxes have cleared their selection, the dynamicly filled comboboxes show the last selected item although the value from the selection itself is null. This looks like a graphics bug to me or am I doing something wrong?
Is there any way around this issue or what is the best method to reset a combobox?
EDIT 2014/08/27:
This is officially not a bug(clearSelection() does not clear value):
https://bugs.openjdk.java.net/browse/JDK-8097244
The official "workaround" is to clear the value of the ComboBox after clearing selection.
cb.getSelectionModel().clearSelection();
// Clear value of ComboBox because clearSelection() does not do it
cb.setValue(null);
It is very simple. You just need to work with the value property of ComboBox. here you go ....
ComboBox c;
c.valueProperty().set(null);
I hope this works for you :-D
I ran into nearly the exact same situation and came across your question while looking for a solution. Fortunately, I came up with a workaround that forces the ComboBoxes to reset. When you reset the data on your pane, instead of doing something like:
cboVet.getSelectionModel().clearSelection();
cboVet.getItems.clear();
do something like this...
parentNode.getChildren().remove(cboVet);
cboVet = new ComboBox(); // do whatever else you need to format your ComboBox
parentNode.add(cboVet);
You'll also need to do a setItems() again on your ComboBox so the new one will be populated. This is not an ideal solution but it seems to be working as I expect the provided clearSelection() method would.
You can retrieve the items and have them all removed:
cboVet.getItems().removeAll(cboVet.getItems());
I've just tested a working solution with the Java JDK 1.7.11:
combobox.setSelectedItem(null);
combobox.setValue(null);
Hope it helps :)
I use reflection with direct manipulation of buttonCell field in ComboBox skin:
#SuppressWarnings({ "rawtypes", "unchecked" })
public static <T> void resetComboBox(ComboBox<T> combo) {
Skin<?> skin = combo.getSkin();
if(skin==null){
return;
}
combo.setValue(null);
Field buttonCellField;
try {
buttonCellField = skin.getClass().getDeclaredField("buttonCell");
buttonCellField.setAccessible(true);
ListCell buttonCell = (ListCell) buttonCellField.get(skin);
if(buttonCell!=null){
StringProperty text = buttonCell.textProperty();
text.set("");
buttonCell.setItem(null);
}
} catch (NoSuchFieldException
| SecurityException
| IllegalArgumentException
| IllegalAccessException e) {
e.printStackTrace();
}
}
I think it's also possible by providing your own buttonCell implementation through buttonCellFactory property
I had the same problem with a ComboBox. The buttonCell of the ComboBox is not updated correctly when I change the items of the ComboBox. This looks like a graphics bug.
I use direct manipulation of buttonCell field in ComboBox.
combo.getButtonCell().setText("");
combo.getButtonCell().setItem(null);
This is the best solution I've found without recreate the ComboBox.
To clear SelectionModel I found nothing better than creating a new instance of Combobox (previous answers update):
myParentNode.getChildren().remove(myCombobox);
myCombobox = new ComboBox();
myParentNode.add(myCombobox);
But this solution evolves other problems: if you use fxml, this combobox will be placed in the wrong place and with wrong parameters. Some fxml parameters are hardly reproduced directly from your controller class code and this is awful to do it every time you need to clear the combobox.
The solution is using custom components instead of creating instances directly in main controller class code, even if these components are standard. This also helps to free some lines in your main controller class by moving component related event methods and other methods to a separate class file, where you use a reference to your main controller class.
How to create custom components in JavaFX FXML Application can be found in http://docs.oracle.com/javafx/2/fxml_get_started/custom_control.htm , but note that CustomControlExample class is not needed for every custom component in your application, if it already has an entry point class with start(Satge stage) method.
How to resolve possible errors with reference from custom component controller class to main controller class can be found in JavaFx: how to reference main Controller class instance from CustomComponentController class?
I need to clear selection of the combo box. And this code worked for me:
List<Object> list = new ArrayList<>(comboBox.getItems());
comboBox.getItems().removeAll(list);
comboBox.getItems().addAll(list);

Resources