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-
Related
I follow these to create checkable combobox
ComboBox of CheckBoxes?
http://programmingexamples.net/wiki/Qt/ModelView/ComboBoxOfCheckBoxes
However when I do a this->Model->clear() then add items, the combobox text (the text combobox displays before user clicking anything) goes blank. The items will still show and are checkable when click on the combobox. I suspect the clear() remove the header and causes this, however I try setHorizontalHeaderLabels etc but I still can't set the combobox text. What am I missing?
Try setting the ComboBox's selected index after you add items. Like:
ui->combobox->setCurrentIndex(0);
Because it could be that after you clear the ComboBox, its display index may have gone to -1 and stayed there even if you add items.
I want to show some text in my program and I tried with TextArea. However, the text shown is changeable. How can I make the text read only?
I did it like this:
#FXML
private TextArea myText;
and then added the following code to initialise():
myText.setEditable(false);
I needed read-only text fields, but setting the disabled property used styling which was not correct in context (in my scenario, the text field was an input to a search function where a value could be fixed in some cases - disabling the text field implied that it was not part of the search, rather than the value was fixed).
In the end I landed up using:
txtInput.setEditable(false);
txtInput.setMouseTransparent(true);
txtInput.setFocusTraversable(false);
This results in a normal looking text field that is non-reactive to the user.
Maybe just a text would serve the purpose.
Or if you want to show the text in a text field, then:
tf.setDisable(true)
In FXML, add editable="false" to your TextField tag.
Or uncheck the "Editable" checkbox in Scene Builder.
I would say just use a Label.
<TextField fx:id="input" disable="true"/>
You can use following statement in order to make text-area object non-editable with auto scrollbar:
textAreaObjectName.setEditable(false);
Hint: After setting the text to that respective textarea object using textAreaObjectName.setText() method.
I'm new. I've determined I cannot make a label "active" and accept keyboard input, so I am trying text fields instead. Seeking advice as to how to kill off the built in keyboard when the user taps the text field, as I want to use my own keyboard (a series of images).
I can determine the active text field (textfield.editing == yes), but when I will kill of the keyboard it seems it also kills off the ability to enter any data into that text field.
Maybe I need to just "hide" the keyboard? Send it off the screen?
OK, I found a way to make this happen. I created some transparent buttons, and laid those over the top of the labels. When the button gets clicked, it designates the label below it should be the active label.
In a separate method, the users text runs thru a few conditions to determine which label (as designated by the transparent button) is active, and the text goes into that label.
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.
I've got two forms, the mainform which opens up a dialog box that has a text box in it. How can I pass the text from the textbox back to the mainform? I've tried alot of different methods but I think I'm missing something simple. Thanks for any help.
The dialog box still exists after it closes. So you can, from the main form, do something like this:
QString text = subform->textEdit->text();
This assumes your dialog box is subform and the name you gave to the text edit box is textEdit. Make sure you make textEdit public in the designer.
If you don't want to make textEdit public, then you can add a getter to subform.
If you use the MVC pattern, you create the model object (container for your data) and pass to the text box to fill in the text value itself. When the dialog is closed, just read the value from the model and put it wherever you need it.