I begin developing with Cocoa. I have an ArrayController which provides datas to a NSTableView with DataBindings.
I added a button on my cellView and want it visible only when the cell (or row, there’s only one column) is selected.
I added a Boolean property to my dataModel « estSelectionne » to activate or not the « Hidden » of my button.
My question:
how to set the value of the « estSelectionne » Boolean? (Tried to addObserver…)
or better, can I set directly the Boolean Hidden in IB, and how?
Thank you in advance
I set the value of my model property "estSelectionne" in an override of NSTableView.isRowSelected and it's OK
Related
I have a combobox (cb). When someone clicks on the associated textfield, I want to clear it. I use
cb.getEditor().setOnMousePressed(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent evt) {
((TextField) evt.getSource()).clear();
}
});
and the result is in cb.getEditor().getText()
So far so good.
If I fill the box via the pull down instead of typing the result is in cb.getSelectionModel().getSelectedIndex();
That's good too. The combobox is populated with an object, not a string, so I can't really use getSelectedItem(). I wish I could.
The problem is, if I try to select something from the pulldown, and THEN use the editor, the selectedIndex() remains set.
How can I clear the combobox selectedIndex when I have a mouse event for the textfield? I can't find a way to get the combobox from the textfield.
I don't know if it's relevant but I also tie the text to the box via TextFields.bindAutoCompletion(cb.getEditor(), cb.getItems()));
From the ComboBox documentation:
Because a ComboBox can be editable, and the default means of allowing
user input is via a TextField, a string converter property is provided
to allow for developers to specify how to translate a users string
into an object of type T, such that the value property may contain it.
By default the converter simply returns the String input as the user
typed it, which therefore assumes that the type of the editable
ComboBox is String. If a different type is specified and the ComboBox
is to be editable, it is necessary to specify a custom
StringConverter.
(my emphasis).
Therefore, you need to provide a converter for your ComboBox that defines how to convert the string the user typed in the combo box editor into an object of the correct type, and conversely how to convert an object of that type into a string to display in the text field.
Once you have done that, the correct way to retrieve the value from the combo box is with
cb.getValue();
I have an editable grid for invoices and a few checkbox columns like invoice, sent to customer / ok to invoice. I have fields updated by/updated on for these boolean fields.
I want to update these two columns if checkbox values have been changed. I am not sure how can I do this. Any help?
The way that I do this is by implementing the INotifyPropertyChanged interface for the SelectedItem property of the DataGrid. Perfect for "I want to update these two columns if checkbox values have been changed".
If you need code just let me know.
In the screen designer for the page select the property from the query (on the left) that represents the checkbox. Then click the drop down next to the "write code" link and implement the method for xxx_Changed.
Here you can then set values for your other fields based on this input.
I have ComboBox With ArrayCollection as DataProvider. Data will come from Databse as ArrayCollection. I'm Adding Item to ArrayCollection "-Select Item-" at 0th index and setting selected index=0 for combobox.
My question is How to disable that(-select Course-) item?
I recommend you to use prompt property of DropDownList or ComboBox for that and combine it with selectedIndex = -1 as initial value.
Worst case an item renderer to show things as disabled. Then simply ignore the click if it has the property disabled. (this implies your list is overloaded with a property like isDisabled.
Mylist.selctedItem.isDisabled
My current CheckedComboBox has a large list of items. I need to have selected list out of those items checked when the drop down is clicked. e.g CheckedComboBox will have P,Q,R and S as the itmes. But only P will have a tick in front of it.
Is there a property for this defined already?
Thanks
The CheckedComboBox control does not provide the CheckedItems (or SelectedItems) property .Use the editor's EditValue property to determine which Items are selected.
I'm using a combo box control and the dataprovider is set as an XML.
After the dataprovider is set, I want to edit the text of the first option and also I need to insert an item in the second position.
How can I do this? Using an ItemRenderer?
Please give your suggestions.
You should edit the dataProvider itself. Make it an ArrayCollection (or something else that implements IList) and your combobox will automatically update as you make changes. Also make sure that the array collection is full of bindable objects.
Changing ArrayCollection is easy. You can just say dataProvider.getItemAt(0).labelProperty = "whatever" -- this assumes you have an object with a property of "labelProperty" and your combobox's labelField is set to it.
To add an item just use dataProvider.addItemAt(item, 1)