I'm a little bit new to J2ME ... I'm using LWUIT as my UI library.
My question is:
I want to display a password TextField that accepts numbers only (I succeeded), but the problem is, when making it accepts numbers only, the last character is not showing however the last character appears when I remove the numeric constraint!!!
i.e.:
password TextField shows last character like: *****m
here is the creation of the TextField, no complexity
tf = new TextField();
tf.setSize(new Dimension(100, 20));
tf.setMaxSize(20);
tf.setConstraint(TextField.PASSWORD);
tf.setInputMode("123");
Form form = new Form();
form.setTitle("Title");
form.addComponent(tf);
form.show;
Thanks in advance,
Arshi
Related
I am using react table. I am calling a method on API (.NET), which concatenates some fields and now I need to display this concatenated field in react table column.
From API I tried to put /n in the column so that it renders a new line on UI (inside react table). But no luck. Example: I need to display
This field is calculated by adding two numbers 10 and 20. Since the
result is greater than 15 you cannot perform this operation.
In the displayed text, what I want is "Since" should start in a new line in react table.
I tried to put {'\n'} before "Since" but it did not work. Any ideas how to achieve this?
The '\n' escape character does not work in HTML. You have to work with
other HTML solutions like using <br> or divs to get a multiline
implementation working.
You solve this quite easily. when getting the string append a special char like the comma (,) or some other char that you are sure would not be used in your original text.
Then get that string to a js variable in your react app.
let multiLineString = "This field is calculated by adding two numbers 10 and 20. , Since the result is greater than 15 you cannot perform this operation";
let lines = multiLineString.split(',')
let linesHTML = lines.map((line)=><div>{line}</div>);
now render this variable anywhere you want, you will get a multi line string implementation.
Of course the better approach would be to get a json array of values from the back end.
I'm trying to do a clear question about the use of the Picker, because my previous one in not enough clear: Codename One - addActionListener of a Picker
The purpose of the Picker is to select one element from a set, such as a string of a set of strings, is it right? So, I want to give the user the opportunity to select a string from a set of strings, each of one corresponds to a language.
The problem is that the use of an ActionListener added to the Picker is not correct for this purpose, because it's triggered by both "Ok" and "Cancel" buttons.
I need to execute some code (to change the language) only and only if the user press "Ok", because executing that code if the user press "Cancel" should be considered an unexpected behavior and a bug (from the point of view of the user).
So my question is how to use correctly the Picker in this use case.
From the CN1 documentation, one way to do this would be :
String [] list = {"one" , "two" , "three"};
Picker picker = new Picker ();
picker.setType(Display.PICKER_TYPE_STRINGS);
picker.setStrings(list);
picker.setSelectedString("test");
picker.addActionListener(l -> System.out.println(picker.getSelectedString()));
Oddly, and as Francesco has pointed out in a prior moment, when you run the application IN THE SIMULATOR, and press the Cancel-Button inside the picker, it prints out the selected string. Same when you press the OK-Button. (Is this intended?)
On installed devices, the results seem to be mixed, as to on some devices the cancel operation does not incur in any action.
I had to do this to avoid triggering another listener on the string (I was using a Property with a change listener) if Cancel was pressed, and I did this by checking the current picker string against the previous selected string to see if it changed. I only updated the field or local variable (Property in my case) if the value changed. Modifying the previous answer's code:
...
private String currentSelection;
...
String [] list = {"one" , "two" , "three"};
Picker picker = new Picker ();
picker.setType(Display.PICKER_TYPE_STRINGS);
picker.setStrings(list);
picker.setSelectedString("test");
picker.addActionListener(l -> {
if (!picker.getSelectedString.equals(currentSelection) {
currentSelection = picker.getSelectedString;
System.out.println(currentSelection);
}
});
How can I get the complete selected text from an AutoComplete TextField?
If I use getText(), I only get the few letters the user has input so far.
Example: I write "flo" and then select "Flowers" from the list, but getText() gives me "flo"
AutoCompleteTextField auto = new AutoCompleteTextField(arrayWithNames);
auto.setMinimumLength(4);
auto.addListListener((ActionEvent evt1) -> {
String lookedFor = auto.getText();
Hashtable<String,Object> match[] = findMatch(lookedFor);
if(hMatch.length>0){
contElements.removeAll();
for (Hashtable<String, Object> Match1 : match) {
...
...//fill the Container with the names found
...
}
}
});
How it works
I am using the AutoComplete TF as a search button.
I have an array with all the names in my list.
Then I populate the Auto with the array.
The user selects a name from the Auto and then I search the value that is being "lookedFor" using the findMatch(). It returns a new array with the found entries.
I need the complete name from the list so I can use the findMatch() method, but when I use getText() from the Auto, it only returns the letters the user entered, and not the whole name, so my method does not work, since I am comparing whole Strings.
(I am using the Auto because it is very convenient if people remember only a part of the name they are looking for)
If you subclass AutoCompleteTextField you can access the selected text internally via getSuggestionModel().getItemAt(getSuggestionModel().getSelectedIndex()). Now you can define a public getter method getSelectedText() or something on your derived class.
I am not sure you are using the AutoCompleteTextBox correctly.
The entire purpose of the AutoCompleteText box is to help you assist the user in selecting from a list of valid requests,
You should not be getting the value of getText() until the user is ready to submit the form where the AutoCompleteTB is located.
This WILL help if you haven't already looked here:
https://www.codenameone.com/javadoc/com/codename1/ui/AutoCompleteTextField.html#getPropertyTypes--
Good luck!
I want to write a Java program that reads the data from a file and stores it in an array. And then generates a random array index and uses it to retrieve a random word from the array to display. Each time the user clicks Next button, the program chooses a new random word to be displayed. I'm trying to add buttons in frame but they won't appear on the JFrame. Following is the code I wrote:
okButton = new JButton ("OK");
Pane.add(okButton);
nextButton = new JButton ("Next");
Pane.add(nextButton);
When the user enters a right answer I want a JLabel to appear saying " Correct answer ". How do I make a JLabel Appear? and when the user closes the frame all the right answers show in a JTextArea.
Can you please help me?
Your question is too much cluttered and vague to me, so providing perfect answer is quite not possible. Following are some useful tips you can use to solve your problem.
read file which contains the word. See File operations in Java and
How to use FileChooser?
Tokenize file and create an array of words. You can use StringTokenizer class for this
Create a method to randomly word from the array. You can use Random class for this.
For the GUI part:
the buttons won't appear on the JFrame
Are you adding panel containing buttons to frame properly?
how do I make a JLabel Appear ?
Add that JLabel to panel/frame and repaint it.
when the user closes the frame all the right answers show in a
JTextArea
Save right answers in some other array (call it answerArray).
Add Window listener to frame to monitor closing of frame.
In close method create a JDialog containing JTextArea and loop over answerArray and append string to textArea. Finally display this new JDialog.
I'm running some simple form tests where values are added fields.
After each value is added to a field:
input.SendKeys(value);
I want to check the value in the field is correct. This may sound unusual but the field may have an ajax search attached and if the search doesn't pull back a match, the field will be empty.
I've tried testing the text value of the WebElement after sending the keys but it always seems to be empty:
bool match = input.Text.Equals(value);
// input.Text always seems to be an empty string
I'm using Selenium 2 with the WebDriver - is there another way to perform these checks? Is there a particular reason why the WebElement is empty even if the SendKeys successfully prints a value (actually in the browser) in to the WebElement (textbox)?
Any help would be grateful.
It may be possible that the text value that you are entering is assigned as a "value" attribute of text box and not as "text"
input.sendKeys(enteredValue)
String retrievedText = input.getAttribute("value");
if(retrievedText.equals(enteredValue)){
//do stuff
}