JavaFX how to show read-only text? - javafx

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.

Related

How to keep focus on Spark TextInput after setting StageWebView source

I have a mobile application that has a Text Input used for searching. Below the search TextInput is a StageWebView. When I set the source of the StageWebView using loadURL() the key input is shifted to the StageWebView.
How can I prevent this?
I think I figured out the problem. When you set the stage property (which is basically setting the visibility to true) that's when it steals the focus. I was showing and hiding the web view depending on if the text input had any text (I was updating the webview source on text change). The fix was to set the web view to visible before putting the cursor in the Text Input. As long as the visibility doesn't change the focus stays in the text input.
I dont know if there is a better way but my solution is to try to set the focus back to the textInput by using myText.setFocus() after your load routine.

How to make taext box work without removing cursor from the text box?

i have a text box, on text_changed event i get one data table which i bind with the grid
view, but every time i have to move the cursor out then only it feteches the datatable,
while i want to make this search like if i as i change the character in the text box
it keep working for all without removing the cursor from the text box,
any suggestion how can i achieve this. Should i use any java script or what.
Have you tried using "onkeyup" or "onkeydown" rather than the changed event?

How to get not truncated text from IUITextField

I have created a custom column header renderer for my AdvancedDataGrid which has a text and a little button inside. Everything works just fine, until a moment when I have to return a headerText by the button click.
Since my custom renderer is an extention of AdvancedDataGridHeaderRenderer it has inherited property label which is IUITextField. So, when I call label.text from inside the custom renderer I get only truncated text, but I need the original one.
Any idea how to get not truncated text from IUITextField? Or maybe the original text is stored somewhere else and I am looking in a wrong place?
You can read the header text from the headerText property of the corresponding AdvancedDataGridColumn

Flex: RichTextEditor -- get and set RICH Text?

Given a rich text editor, I want to save the "rich" text to a database, and load it later.
So how can I get and set the rich text?
I looked at the API and there is a property called text which is only PLAIN text, not what I need. There is another property called textSnapshot which sounds like maybe thats what I need to use, but its READ-ONLY so I can't set it?
Is there a way to do this?
Thanks!
UPDATE
It turns out I am only going to save it from a RichTextEditor, and I need to set it has htmlText on a Text control,
so is there a way to get the rich text and convert it to hmtlText?
I'm not sure what you mean by rich text. The htmlText holds all the informations which the components use for rendering the HTML text, and which is also the base of the RichTextEditor rendering. You can get and set it, and that's exactly what you need to store in the DB and put the text back after retrieving it. There's no export it as rtf out of the component. It's rich in the sense that it's more than a simple textInput :)

Passing variables from one form to another in Qt

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.

Resources