JFXtras / jfxtras

A supporting library for JavaFX, containing helper classes, extended layouts, controls and other interesting widgets.
http://jfxtras.org
Other
599 stars 123 forks source link

Persistent promptText #75

Closed Maxoudela closed 7 years ago

Maxoudela commented 7 years ago

The prompt text implemented by JavaFX (As in Java 8) is invisible when a TextField has the focus. It may be good or bad in certain situation, but it's that way.

Now suppose you have an application with several CalendartextField one below each other. And you have to type some dates with the keyBoard. But these calendars have their own Date formatter. So one will want "DD/MM/YYYY" as input, the other will want "MM/DD/YYYY" for example. (Yes this can happens in you have different Locale...)

So you put the format into the promptText, but each time the user goes to one Calendar to another, the prompt Text is gone because of JavaFX default implementation! So the user is like "what should I type?".

I've looked over and find this solution here : https://stackoverflow.com/questions/25125563/clear-prompt-text-in-javafx-textfield-only-when-user-starts-typing I can put this solution on my application easily because I only need to modify the CSS. But I'm wondering if this behavior should not be implemented by default on JFXtras textfield.

Maxoudela commented 7 years ago

When you look at normal browser behavior, it's what you see.

I've made a little video in my application showing the issue when the user wants to input a Date into a SpreadsheetView : https://gfycat.com/SpiritedSmoggyAcornweevil

tbee commented 7 years ago

Well, if I understand it correctly, it is a JavaFX TextField problem. The date/time textfield reuse the prompt text, so Jonathan should fix it. Would it be of much use if only the date/time textfields would have the correct behavior?

OTOH (I get your point), if we can fix it until the TextField fixed, why not...

Maxoudela commented 7 years ago

Well at first, we had the behavior in the common browser where the prompt text was seen until something was typed. But this issue came in : https://bugs.openjdk.java.net/browse/JDK-8100686 and said that in Windows, when the focus was in, the prompt text should be gone..

So this is never going to be fixed in JavaFX I believe..

I can directly have the behavior I want in my application by doing the CSS trick, so really, it's whether your want this behavior by default in your textField date/time controls or not.. Thus the "enhancement" tag..

tbee commented 7 years ago

Well, I think the TextFields should behave as normal textfields do. So my question is: why do you want it differently? As I see it, your problem comes from that there is no textfield visible until the focus is placed. In that scenario you create the textfield AND put the focus in there, so the prompt text is never displayed. This holds for all textfields, so we should find a solution that you can apply to all textfields, like a decorator maybe? Can a TextField know when it is being used in a table?

tbee commented 7 years ago

But this is something that is an issue for TableView as well, isn't it?

Maxoudela commented 7 years ago

Yes It's an issue in the TableView because of what you described. As soon as the TextField is shown, the focus is in.

I though this issue would be annoying to other person, if not, we can close this issue and keep the current behavior.

tbee commented 7 years ago

I think you are right and that your solution is better for a TextField in a TableView. But it is a problem for all TextFields in TableView. I do not think patching just the JFXtras date textfields is the way to go. We need a solution for all textfields.

tbee commented 7 years ago

Maybe it is possible to create a TableViewPromptTextPatch. Any TextField that is used in a TableView should be added to an instance of that class. The patch class will add the prompt.css (that is a resource to the patch class) to the stylesheets of the TextField and start listen to the text-property, adding or removing the prompt class as needed. In this way you have one solution for all TextFields.

Or even better: we create an extended version of TableView in JFXtras with this functionality build in.

Maxoudela commented 7 years ago

Well, this promptText is annoying in the date because we really want to parse the date. Other Textfields are usually used for double or integer, and I don't put any promptText on them because I do not expect any particular format. Just a number.

I think we could go simpler if we want to patch the TableView (as a side-note, I'm using that in the SpreadsheetView of ControlsFX, not in the TableView right now), by adding in the css this :

TableView .text-field{
    -fx-prompt-text-fill: derive(-fx-control-inner-background, -30%);
}

Each TextField in the tableView will have the prompt text "fixed" I believe.

tbee commented 7 years ago

Hmmm, you simply need to test. TextField will change things in its CSS in order to hide and show the prompt text, and this should override (negate) the normal behavior. I'm not sure it will.

You could try and convince the spreadsheet guy to 'handle' the textfield. But since you specify which editors to use, the TableViewPromptTextPatch should work. Never the less I'm pretty sure it should not be done as default behavior on CalendarTextField and friends, since it really is a TableView induced problem and should be handled for all textfields.

Maxoudela commented 7 years ago

I just tested it on the SpreadsheetView by adding

.spreadsheet-cell .text-field{
     -fx-prompt-text-fill: derive(-fx-control-inner-background, -30%);
}

And it works. The Textfield is actually not changing things on the CSS, or at least it is not bothered.

By the way, I'm the "Spreadsheet guy" of ControlsFX^^. I created the SpreadsheetView. I will see what I can do, but on my application, the issue is fixed by simply using css. We can close this issue regarding JFXtras.

tbee commented 7 years ago

Very good spreadsheet guy. :-)