Why doesn't JavaFx choice box doesn't automatically update a property? - javafx

This is a simplified version of my case.
Layout
A choice box with 3 options.
A textarea T1
An input text field.
A textarea t2
Expectation
When the user clicks on an option the selected option is displayed in the T1 instantly.
T2 displays instantly what's currently present in input text field.
Implementation so far
I added a method for onKeyTyped for the text field and #2 works.
I added a method for onMouseClicked for the choice box. #2 doesn't work instantly. It takes another click on the choice box or key press on the text field to display the new value in T1. I also tried onAction and that too didn't work.

For java
inputTextField.focusProperty((observable, oldValue, newValue) - > {
if(newValue) t1.setText(inputField.getText());
});

Related

JavaFX combobox set PromptText after selection option

I've set a prompt text for my combobox which appears before selecting an option.
After the user selects an element in the ComboBox I want that text to appear again, but I don't want it to be a ComboBox item.
I tried clearing the selection and setting the prompt text again, but no text is appearing, it's empty.
How do I need to do it?
The javadoc states:
public final void setPromptText(String value)
Sets the value of the property promptText.
Property description:
The ComboBox prompt text to display, or null if no prompt text is displayed. Prompt text is not displayed in all circumstances, it is dependent upon the subclasses of ComboBoxBase to clarify when promptText will be shown. For example, in most cases prompt text will never be shown when a combo box is non-editable (that is, prompt text is only shown when user input is allowed via text input).
https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/ComboBoxBase.html#setPromptText-java.lang.String-

How to call control ID in Client side human interface?

I have two templates built in coach view and I have added them to a client side human interface. How do I implement a common logic between them?
Coach view 1
--------------------------------
button 1 button 2
--------------------------------
Coach view 2
----------------------------------
Text box
----------------------------------
I have two radio buttons in one and a text box in the other. If I press either one, I want to set a text, e.g. hello and bye.
You should give each button their own control id name, so you know which button they are, like "button1", "button2". Then bind each button to the same string variable, which needs to be a configuration variable in the view or business object bound to the view. When each button is clicked, they will cause the change event to fire because the bound variable is updated, and the value or property of that change will be the control id of the button clicked. I am assuming your text box is bound to a variable in it's coach view also. When you detect a change event, if the value is "button1", then set the value of the string of your text box to whatever text you want. If the value is "button2", set the value of the text box to the text you want. I don't have access to the code I recently did for this or I would give you a more accurate syntax.
I would probably have a configuration variable for each coach view above, one named something like "buttonClicked" and bind each button to it. Then one bound to coach view 2 like "displayText". If either one changes, it's going to fire off a change event, which is why you want to use if/else to make sure the change is "button1" or "button2". If button1 changes, then this.context.config.displayText.setValue("button1 clicked").

Custom TextInput component loses focus but still contains cursor?

I have a custom TextInput that listens for the FocusEvent.FOCUS_IN and FocusEvent.FOCUS_OUT events:
textDisplay.addEventListener(FocusEvent.FOCUS_IN, onFocusInHandler);
textDisplay.addEventListener(FocusEvent.FOCUS_OUT, onFocusOutHandler);
My onFocusInHandler function basically removes a "promptview" that tells the user to type in a value, with the onFocusOutHandler doing the opposite.
For example, if the TextInput text was backspaced to a blank value and the user clicks out of the TextInput box, it would show a "Please enter a value" light-gray prompt in the TextInput.
This works fine until the user clicks our custom "Clear" button. The clear button sets the text to "", and I can tell the FocusEvent.FOCUS_OUT is received because the prompt text is set to visible (its not being set anywhere else). The problem is, the cursor remains in the box as if it still has focus, so if the user immediately starts typing, both the prompt text "Please enter a value" and the user-entered text appears over the gray text, which looks pretty ugly and unreadable.
Why does the TextInput receive the FocusEvent.FOCUS_OUT event if it's not actually losing focus? Is there any way I can get around this?
Option 1. Use the Spak TextInput in Flex 4.1 or 4.5. This already provides a promptDisplay by default (as mentioned in the comments)
Option 2. Take a look at the focus-skin. This skin class is usually placed on top of the normal skin. There could exist some focus ambiguity between these two. Try using a custom focus-skin without a textDisplay and clear button.
Option 3. Not only use a focus event to show or hide the prompt, but also look at the content of the TextInput. You don't want to display a prompt when the text is set by binding as wel.

Setting Record Data resets ToggleButton

I am facing a strange problem.
I have created a normal ext-gwt grid with two columns. One column displays a number and the other renders a ToggleButton. As soon as the ToggleButton gets pressed a small window appears with: 1- a textfield (to enter a number), 2- an ok button.
When the ok button is pressed the column containing the number should change it's value to the value given in the small window's textfield. This is the final picture I want to have. Easy! right?
The problem comes now. This is what is executed when the ok button is pressed in order to change the value in the column:
Integer value = new Integer(10);
Record record = store.getRecord(bean);
record.set("employeeNumber", value);
Although the value is actually changed using this code, it makes something weird. The ToggleButton remains in the "un-pressed" state whenever this code is executed. If I remove the last line, the ToggleButton functions normally again (gets pressed).
Any idea how to solve the problem of the ToggleButton?
Thank you
So you want the toggle button to change state after setting the value, right?
How do you get the toggle button into the grid?
I assume by using a custom widget renderer? In this case the render(..) method will be called more than once, returning a fresh and un-toggled button each time which will be displayed...
Maybe you could post some more code...?

Flex edit DataGrid cell on click only when previously selected

I need to modify the behaviour of an editable datagrid to this:
-Single-click on a row, doesn't make the cell show a text input field (only selects the row)
-Double-click on a row, doesn't make the cell show a text input field either
but
-Clicking a cell in an already selected row, shows a text input field ready to be edited.
I belive this is how for example iTunes works.
I found a solution.
I ended up using the ListEvent.CHANGE to tell if the selectedIndex index had changed,
and then the preventDefault on ITEM_EDIT_BEGINNING if it was.

Resources