1

I have a large number of textfields in tabs on screen - each of them must be validated. If there is an error in the input, I want some indication that a specific field has an input error.

Not every culture understands that red border means error, so I need to have the text 'error' somewhere near, over or across. For instance, to have a titled border over the text field in red saying 'error' like Java Swing has. So in the base class of the tab controllers - TabController, I have methods like

validateNumber(TextField field, String validRangeRegex); 
validateIpaddress(TextField field, String validRangeRegex); 

This question asks the same but the solution involves subclassing from StackPane. GroupBox / TitledBorder in JavaFX 2?

How do I implement titled border without subclassing from TextField?

If it isn't possible in raw JavaFX, I was wondering if a JavaScript handler can write "error" over the text field? http://docs.oracle.com/javafx/2/api/javafx/fxml/doc-files/introduction_to_fxml.html#script_event_handlers

Community
  • 1
  • 1
likejudo
  • 3,396
  • 6
  • 52
  • 107

2 Answers2

0

Can't you just give the textbox an error style class with a red background-color? And install a tooltip on the textbox where the error occurred?

I know this might not be a direct answer but I don't think it is possible without subclassing.

Installing tooltip:

TextBox t = (TextBox) o;
t.setTooltip(new Tooltip("Please enter a value"));
t.getStyleClass().add("error");

CSS:

.error {
    -fx-background-color: #FBE3E4;
    -fx-text-fill:#8a1f11;
}
Perneel
  • 3,317
  • 7
  • 45
  • 66
  • I need to have the words "error" near or over the TextField. Not everyone understands a red border is error. Changed the question title to say "How to write over or across a TextField in JavaFX2?" – likejudo May 24 '13 at 15:09
0

I found this question - I shall use an image icon that says "error". Adding a small picture on the right side of textField with CSS

Community
  • 1
  • 1
likejudo
  • 3,396
  • 6
  • 52
  • 107