XdevTextField
The XdevTextField is a single-row input field and one of the most frequently used form components, which can be persisted via the XdevFieldGroup.
Important properties:
TextChangeEventMode - Determines when exactly the textChange event is triggered.
LAZY - Default setting. The event is triggered only if there is a timeout after the last change. The length of the timeout can be defined in Properties > Misc > TextChangeTimeout.
- EAGER - The event is triggered at each keystroke.
- TIMEOUT - The event is triggered only if there is a timeout after the last change.
TextChangeTimeout - Defines the length of the timeout, after which the textChange event is triggered, in milliseconds.
Important events:
textChange - Is triggered after a brief delay following changes to the content, for example adding or deleting characters. The exact time at which the event is triggered can be defined under Properties > Misc > TextChangeEventMode.
MiscÂ
valueChange - Is triggered after changes to the content, mainly by adding or deleting characters, however only if the UI component loses the focus.
Examples:
Allocate content - Allocates a text as string to the XdevTextField. This may trigger a textChange or valueChange event.Â
This is the simplest type of allocation. However, it is 100% functional only with strings. When this method is used, diverse converters deliver an unsatisfactory output.textField.setValue("Hello 123 !!!");
Allocate content - Allocates a specific value to the XdevTextField. As an example, a BigDecimal data type for currencies or Double for specific formatting with decimal places, etc.
When this type of allocation is employed, the delivered converter functions optimally.Property<BigDecimal> betrag = new ObjectProperty<BigDecimal>(new BigDecimal(100), BigDecimal.class); textField.setPropertyDataSource(betrag);
or
Property<Double> betrag = new ObjectProperty<Double>(new Double(100), Double.class); textField.setPropertyDataSource(betrag);
Change content - If a property is already allocated to the XdevTextField (refer to example 2), the value can be changed directly in the property in this abbreviated form without setting a new data source.
textField.setConvertedValue(200);
Read content
String content = textField.getValue();
Delete content - Deletes the entire content in XdevTextField. This may trigger a textChange or valueChange event
textField.clear();
Set cursor - Set the cursor to a specific position. The position is specified as an int value.Â
textField.setCursorPosition(10);
Set focus: Allocates the focus to the XdevTextField. This can trigger a focus event, if necessary.
textField.focus();
Select content
textField.selectAll();
Check if the field is empty and or null.
boolean empty = textField.isEmpty(); if (empty) { doSomething(); }else { doSomething(); }
Check if anything has changed
boolean modified = textField.isModified();
Go to XdevTextField Javadoc
Tips:
Convert string to integer: If the content of the XdevTextField is an integer, with which you want to calculate further, you must convert the string with the Integer.parseInt(String s) method into an integer. The method accepts only a string with characters. Only the characters + and - at the start of the value are permitted. Â
String content = textField.getValue(); Integer value = Integer.parseInt(content);
Convert integer to string: When you want to assign an integer to an XdevTextField, you must first convert it into a string.
Integer value = 100; String content = Integer.toString(value); Â textField.setValue(content);
XDEV Software Corp. - One Embarcadero Center, San Francisco, CA 94111, US
Copyright © 2015. XDEV Software Corp. All rights reserved.