Changing colour of the text in Javafx textfield WHILE typing - javafx

i'm new to javafx. currently i'm trying to change the colour of a text INSIDE a textfield as the user is typing. I'm not trying to change the colour of the text somewhere else but in the textfield itself.
I've searched everywhere and everyone is talking about how to change the colour in another textfield, using Text object or TextFlow. But I'm trying to change the colour of a particular word when user is typing.
For example, if user type " go to school by 2pm" , i would like to change the colour of the word "by" to green (in the textfield itself when the user is typing).
is there anyway to achieve this? Or can this not be done?
Thank you in advance :)

You cannot change the color of an individual word in a TextField, only all words in the TextField. The closest you can do is subvert the selection highlight mechanism, but that is really a bit of a hack and isn't really applicable for your context where the user is actively typing in the TextField.
Rather than using the inbuilt TextField (which is not a good fit for your requirements), you might want to investigate alternate options such as Tomas Mikula's RichTextFX control.

Related

What are the advantages of putting TextField inside Button (JavaFX)

In SceneBuilder it is possible to put TextField inside a Button:
Is it for just decorative purposes or it has some functionality like when clicking button it gets child info and so on? If it has some functionality, are there any examples?
From the documentation:
A simple button control. The button control can contain text and/or a
graphic.
The graphic is changeable for every subclass of Labeled.
You can put any node as graphic into e. g. the button. It gives you a very high level of customization.
A good example is the customization of the header of a TitledPane.
As for your concrete example I see no advantage, rather a disadvantage as it's not common to have a textfield inside a button. But you nevery know with what people come up with.

Text in flash button symbols all change at once (Actionscript 2)

I have reached an impass which means I have to spend many hours doing something in a very tedious way because I can't work out a way to do it quickly, here is my problem.
In flash if I make a button that consists of a rectangle and a text field then make it all a button symbol, if I then copy the symbol to multiple instances on screen and change the text in one of them, it changes in all of them because I am changing the symbol.
How can I overcome this, perhaps with actionscript? I tried writing.
button1.text1.text = "test change button text"; on the main canvas (and giving one button a name of button one and the text field within it text1) but it doesn't work.
The only thing I found that works was to make multiple symbol copies of the button but then if I want to change the colour or dimensions of all the buttons it takes ages.
Is there a better way? Using actionscript 2 perhaps, or just some property of the button to allow individual text?
I attempted your situation... and I didn't run into your problem. Text boxes are individual values, provided that the text box is dynamic or input
I think that what may solve your problem is checking what kind of text boxes you are working with. Look in the properties panel; does it say "dynamic"?

Defining own style for Hyperlink in JavaFX

I am new to JavaFX programming, and I need to develop an own style for Hyperlink objects. Basically is:
black color when is created, disabled, pressed and any other case before the following second case.
blue color after an email, that is written in this hyperlink, was succesfully sent.
Thanks in advance.

Keep Selection in JavaFX Textfield even if application is not focussed

Background:
I'm trying to implement a find/replace function for java-Fx table view. Whenever I find an occurance of the text to find, I switch the table view into edit mode and select the text found programatically in the textfield which is used during edit mode.
The focus in this situation remains in the modal find/replace dialog, so the selection in the textfield is not visible until I close the modal dialog.
The problem:
A textfield in Java-Fx shows it's selection only while it has the focus (as its standard behaviour). When the Java-Application loses focus the selection becomes invisible, when it gets the focus back the selection is visible again.
Here is the question:
Is it possible to keep the selection visible in a textfield though focus is lost?
What I tried:
I expected that CSS could help here:
textField.setStyle("-fx-highlight-fill: lightgray");
This changes the color of the highlighting but
I wanted to keep the original color for the focussed Textfield
I wanted to change the color from"invisible" to "lightgray" only for
the non-focussed Textfield
What is the correct way?
Or is there a way to highlight text in a TableView without activating the TextField?
Thanks
Ingo
If I am understanding correctly, the solution will be in the modality of your find/replace dialog.
It works for me when I do the following: Note that the java file this is written in extends Stage. If you are not extending stage then just call the methods on your find/replace stage.
owner = myApplicationStage;
initModality(Modality.NONE);//important for the solution!
initOwner(owner);
initStyle(StageStyle.UTILITY);
setScene(myFindAndReplaceScene);
stage = this;
stage.show();
This works perfectly for me, if you have any problems then hopefully I can help.

FlashBuilder4.6/AIR Mobile TextInput Broken

I am creating a mobile app using FB4.6/AIR. I am running into several issues when I have TextInput fields in my view. If I have a TextField (StageText) that has text pre-populated in it (i.e. from a data object), when the view loads, the TextField will flash the text until it eventually stops and the text disappears. Upon selecting the TextField, the text will reappear. Obviously, this is not an ideal situation. So, after doing some research, I bypassed using the StageText by using the SkinClass - 'spark.skins.mobile.TextInputSkin'. This fixed the flashing text issue, however, now upon entering text in the TextField, after a certain point, the text seems to duplicate itself several times over, so that the the word, in this case an email address, becomes unrecognizable (i.e. John.Doe#MyEmail.com would become John.Doe#MyEmail.com#MyEmail.comJohn.Doe#My).
Obviously, I need to find a solution for one of these situations. Suggestions?
Thanks, in advance.

Resources