Field validation text for the time format
Hi all
I have been breaking my head for almost 2 weeks, but am not able to figure it out... Please help me solve the riddle... here, it will:
In a text field, I want to perform an operation in the following way:
> a text default to 00:00:00 is defined at the moment as the text field is for the moment and the length in characters of the field is 8.
> if the cursor is in position 0 (zero) and if I press a number of key it should replace the value of the 0 position and move the cursor to the next position.
for example: 00:00:00
20:00
explanation : now the cursor is in position 0 and I press the 2 key it should replace the value 0 in position 0 and den move the cursor on the position 1 ie. next position...
When I press a button not digital it shouldn't replace the value, but the slider should move to the next position.
This seems to work ok. You need to test more, however. I've added a few properties for the hours, minutes and seconds as well.
import java.util.regex.Pattern; import javafx.application.Application; import javafx.beans.binding.Bindings; import javafx.beans.binding.IntegerBinding; import javafx.beans.property.ReadOnlyIntegerProperty; import javafx.beans.property.ReadOnlyIntegerWrapper; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.IndexRange; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class TimeTextFieldTest extends Application { @Override public void start(Stage primaryStage) { VBox root = new VBox(5); root.setPadding(new Insets(5)); Label hrLabel = new Label(); Label minLabel = new Label(); Label secLabel = new Label(); TimeTextField timeTextField = new TimeTextField(); hrLabel.textProperty().bind(Bindings.format("Hours: %d", timeTextField.hoursProperty())); minLabel.textProperty().bind(Bindings.format("Minutes: %d", timeTextField.minutesProperty())); secLabel.textProperty().bind(Bindings.format("Seconds: %d", timeTextField.secondsProperty())); root.getChildren().addAll(timeTextField, hrLabel, minLabel, secLabel); Scene scene = new Scene(root); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } public static class TimeTextField extends TextField { enum Unit {HOURS, MINUTES, SECONDS}; private final Pattern timePattern ; private final ReadOnlyIntegerWrapper hours ; private final ReadOnlyIntegerWrapper minutes ; private final ReadOnlyIntegerWrapper seconds ; public TimeTextField() { this("00:00:00"); } public TimeTextField(String time) { super(time); timePattern = Pattern.compile("\\d\\d:\\d\\d:\\d\\d"); if (! validate(time)) { throw new IllegalArgumentException("Invalid time: "+time); } hours = new ReadOnlyIntegerWrapper(this, "hours"); minutes = new ReadOnlyIntegerWrapper(this, "minutes"); seconds = new ReadOnlyIntegerWrapper(this, "seconds"); hours.bind(new TimeTextField.TimeUnitBinding(Unit.HOURS)); minutes.bind(new TimeTextField.TimeUnitBinding(Unit.MINUTES)); seconds.bind(new TimeTextField.TimeUnitBinding(Unit.SECONDS)); } public ReadOnlyIntegerProperty hoursProperty() { return hours.getReadOnlyProperty(); } public int getHours() { return hours.get() ; } public ReadOnlyIntegerProperty minutesProperty() { return minutes.getReadOnlyProperty(); } public int getMinutes() { return minutes.get(); } public ReadOnlyIntegerProperty secondsProperty() { return seconds.getReadOnlyProperty(); } public int getSeconds() { return seconds.get(); } @Override public void appendText(String text) { // Ignore this. Our text is always 8 characters long, we cannot append anything } @Override public boolean deleteNextChar() { boolean success = false ; // If there's a selection, delete it: final IndexRange selection = getSelection(); if (selection.getLength()>0) { int selectionEnd = selection.getEnd(); this.deleteText(selection); this.positionCaret(selectionEnd); success = true ; } else { // If the caret preceeds a digit, replace that digit with a zero and move the caret forward. Else just move the caret forward. int caret = this.getCaretPosition(); if (caret % 3 != 2) { // not preceeding a colon String currentText = this.getText(); setText(currentText.substring(0, caret) + "0" + currentText.substring(caret+1)); success = true ; } this.positionCaret(Math.min(caret+1, this.getText().length())); } return success ; } @Override public boolean deletePreviousChar() { boolean success = false ; // If there's a selection, delete it: final IndexRange selection = getSelection(); if (selection.getLength()>0) { int selectionStart = selection.getStart(); this.deleteText(selection); this.positionCaret(selectionStart); success = true ; } else { // If the caret is after a digit, replace that digit with a zero and move the caret backward. Else just move the caret back. int caret = this.getCaretPosition(); if (caret % 3 != 0) { // not following a colon String currentText = this.getText(); setText(currentText.substring(0, caret-1) + "0" + currentText.substring(caret)); success = true ; } this.positionCaret(Math.max(caret-1, 0)); } return success ; } @Override public void deleteText(IndexRange range) { this.deleteText(range.getStart(), range.getEnd()); } @Override public void deleteText(int begin, int end) { // Replace all digits in the given range with zero: StringBuilder builder = new StringBuilder(this.getText()); for (int c = begin; c23) { return false ; } if (mins < 0 || mins > 59) { return false ; } if (secs < 0 || secs > 59) { return false ; } return true ; } catch (NumberFormatException nfe) { // regex matching should assure we never reach this catch block assert false ; return false ; } } private final class TimeUnitBinding extends IntegerBinding { final Unit unit ; TimeUnitBinding(Unit unit) { this.bind(textProperty()); this.unit = unit ; } @Override protected int computeValue() { // Crazy enum magic String token = getText().split(":")[unit.ordinal()]; return Integer.parseInt(token); } } } }
Tags: Java
Similar Questions
-
I created a form with fields default text for a user to update/customize. Is there a way to style of the text, so I can quickly identify the changes to the default text in a field?
You can use a validation script customized to each text field that looks like:
event.target.textFont = event.value = event.target.defaultValue? font. HelvI: fonts. Helv;
This will make the text italic (Helvetica) when the field value is the value default and regular otherwise. There are other properties that you can use instead, as the field color, border width, background color, text or text size...
-
I want to configure lightning with the time format 24 hours rather than the AM/PM format, but cannot find it in the options. Thanks for the help!
You will need to set it for your operating system. Lightning uses the format of the OS.
-
Hello
just a small comment on French and the time format: now, it is written in non-French format (0:00-12:00 a.m..) while in France, we use a time format 24 hours (0 h 00 - 24 h 00)
Thanks for the comments. We relaierons this to our product team.
Best,
Socialcast VMware team
-
I created a pdf document using Adobe Acrobat XI base and want to put a link on each page, return to the table of contents. However, the tool "Add a link" I cannot place this link on each page at a time. Accordingly, I used the tool 'Add a button' interactive Actions that allows me to do what I want. However, when I enter the name of the button, add background color (or not) and register, the name of the text for the button does not show, only the background appears (or nothing if I select no background). The button works, it just is not labeled. Any help will be appreciated.
This is the area of the label, under Properties - Options.
The game, 23:02, charlesc90551452, [email protected] , 14 may 2015
-
triggering event for the time of day
I'm trying to put in place a system that requires taking several samples per day at the fire time (at irregular intervals) and then repeat it every day for a week or two. So far, I have tried to use a TimeStamp control array, but I'm not getting much. Does anyone has any ideas on how to do it, or can point me to an example that I missed in my research.
Thank you
So what I would do, is create a loop of events with a single event - a timeout. Conduct of this event would be a picture of the time when an action should be performed. The loop starts, remove the first item and subtract the current time of the time goal. This will give you the time in seconds before the event. Multiply by 1000 to get the number of milliseconds before the time runs out. Feeding this value for the time-out. Then each timeout event fires of time, of the index to the next item and calculate a new delay.
Mike...
-
Name of the table to query for the time window of work
I am trying to build a query for a list of jobs in tide. Anyone know what table is for the time window? Please notify. Thank you.
Hi Warren, according to me, this is the jobdtl table.
jobdtl_fromtm and jobdtl_untiltm
-
How to set remote spaced further icon to display more text for the name below?
Windows 7 desktop has many icons with similar names. I want that name under the icon. How to set remote spaced further icon to display more text for the name below?
Right-click on the desktop and select Personalize.
Select the color of the window
Select the appearance settings advanced.
Select the drop down next to the element
Go down and select icon spacing (Vertical)
change spacing next to size according to the needs.
-
API no valid key for the work day
An error occurred during the recovery and send documents EchoSign.API no valid key for the day's work...Kindly help?Hi Mary,
Instead of the API key, I suggest you use the key to integration as key of the APIs have been deprecated. If you have a global account, then go to account > Adobe DC eSign API and click integration key link to create the key.
Kind regards
Ana Maria
-
Get the following error when trying to install adobe reader in Windows 10... "the file 'C:\ProgramData\Adobe\Setup\{AC76BA86-7AD7-1033-7B44-AC0F074E4100}\AcroRead.msi' is not a valid package for the Adobe Reader XI product... How can I solve this problem? Thank you.
Hi JFO58,
I recommend you to run on your system cleaning tool:Download Adobe Reader and Acrobat tool - Adobe Labs
Later, try to install reader again by using the following link: Adobe Acrobat Reader DC install for all versions
Kind regards
Rahul -
I bought and installed Photoshop elements 13. The program does not open but says I have to register on my Adobe ID that I have. Then, I get a box saying I'm not online or my computor clock is out of adjustment. The clock is correct for the time being, and I am on the line what should I do?
See the link below:
Photoshop elements 13 - can't get a response code in the offline activation method
-
Change the color of text for the hyperlink in the Blog module
How to change the color of text for the hyperlink in the Blog module? I tried to add the code:
text-decoration: none;
in the HTML code, but maybe I only am not inserted correctly.
Any ideas?
Thank you!
Hi Casey,.
Make sure also that you have nothing referring to the color attribute in your CSS. For example on my test site screen.css control it is here an example of using Firebug to find this.
If still stuck and specify the site and help further.
Kind regards
-Sidney
-
tests of the device for the time of the ASM and Network Protocol (NTP)
Hi all.
I try to install Infratruction grid Oracle 11 g R2 amd oracle Linux OS but
I got the following error.
tests of the device for the time of the ASM and Network Protocol (NTP)
can someone guide me what should I do for them?in RAC 11 GR 2, the option to synchronize the time between the nodes are ntp or ctss.
If you want to use ntp add the - x option in/etc/sysconfig/ntpd (for example OPTIONS = "-u ntp:ntp Pei /var/run/ntpd.pid x")
Hope this helps
-
'Java' is not a valid parameter for the language attribute
Got an exception on Weblogic 10.3 after deployment in the JSP as "the 'Java' is not a valid parameter for the language attribute.
I installed weblogic 10.3 and a deployed application.
"The JSP containing code such as < % @ page language ="Java"import =" is in error.
The error message looks like this
'Java' is not a valid parameter for the language attribute.
Please let me know if I need to include a few pots or change some settings.
Thanks and greetings
MaurySeems to be a syntax problem. Have you tried language = "java" instead of language = "Java"?
-
Enter the text for the form field and do to repeat in the following pages
Hi - I'm working on an interactive form of 14 pages. There are two text fields that must appear on the bottom of each page.
Anyone know if it is possible for the user to these fields in competition once and while the text automatically repeat on the following pages?
I create the form in InDesign CS6 (I CC, but it runs like a turtle).
Any help much appreciated! Thank you.
Form fields with the same name will have the same value, so just name them
Similarly.
Duplicate a field on several pages is easily achievable in Acrobat, by the way.
There is a built-in function that allows you to do when you right click on a shape
in form editing mode.
Maybe you are looking for
-
I have 2 iphones with separate lines and one is for daily use and the other is for use of outdoor activities. My question is what is the best method to configure other phone as to causes no conflicts? I'll be maintaining one of these phones. Thank yo
-
How do you show your camera (connected via USB) in the Finder?
-
After the installation of Safari does not
After you install the update to 10.11.3 when I open safari and try to type in the search bar nothing happens, if I put a url where it will take me on this site, but then I can't tape in this bar at most.
-
I recently tried to install SP2 to Vista, but it failed. I tried all the resolutions posted, but it is not always correct it. Later, I started my Vista (automatically restored to SP1) and it came with a mistake, "Microsoft Mobile PC presentation adap
-
Server R2 2012 - don't click right button start - no logoff
In Server R2 2012 there is no logoff when right click on the Start button. I understand that logging using the Metro Interface (Start Menu), you can, but if you include stop and restart right on the start options button I'd logoff should be there as