Formatting Strings in TextField JavaFX - string

In my JavaFX application I am trying to format a String and then push it to TextField.
This is my code:
String result = "No of Rows Returned : " + repairHeaderEntities.size();
if(null!=repairHeaderEntities && repairHeaderEntities.size()>0){
result = result + "\n" + "\nRepair Status Code: "+entity.getRepairStatusCode();
analyzeResult.setText(result);
analyzeResult is the TextField fx id.
But in the output I am getting the following:
No of Rows Returned : 1Repair Status Code: ENDE
As you can see there output is not moving to a new line and is coming up in the same line.

From the documentation for TextField:
Text input component that allows a user to enter a single line of unformatted text. Unlike in previous releases of JavaFX, support for multi-line input is not available as part of the TextField control, however this is the sole-purpose of the TextArea control.
Use a TextArea in place of the TextField.
If you do not want the user to be able to edit the text in the text control, you could also consider using a Label instead.

Related

Read a string from a point

Truth is, I don't know if I asked the question correctly, but here is the explanation:
I created a texbox that works as a command line. You enter data and depending on what is written, it will perform several functions: for example: change the color of a panel, button, letter, etc.
Now I try that when I enter "color.Red" the program detects the word "color" and then knows that all that appears after that word is the color that the user wants to change so far it is like this:
if (e.KeyCode == Keys.Enter) // if user presses enter
{
System.Drawing.Color myColor = System.Drawing.ColorTranslator.FromHtml (command_txt.Text); // reads the content of the textbox and passes it to html language that gives us the color
this.BackColor = myColor; // at the end, set this color to the bottom of the form
}
As you can see, I only made the program able to read the color.
Is there a way to run this code only when the user enters "color" + "(whatever color you want)".?

How to convert the normal text to bold text?

I have this code in my Dialog:
//other code
dialog.addText(strFmt("Delete this field's value: %1?", MyTable.FieldTable));
//other code
I have an output looklike:
I know the strUpr function:
dialog.addText(strFmt("Delete this field's value: %1?", strUpr(MyTable.FieldTable)));
Does there exist a method or function to convert only the FIELDValue to bold text?
You can set the bold property to 7 on FormBuildStaticTextControl.
Control can be obtained via the control method on DialogText returned by addText method.
The integer that is returned contains the weight of the font as follows:
0 Use the default font weight.
1 Thin.
2 Extra-light.
3 Light.
4 Normal.
5 Medium.
6 Semibold.
7 Bold.
8 Extra-bold.
9 Heavy.
Example:
Dialog dialog = new Dialog();
DialogText dt = dialog.addText("Test");
FormBuildStaticTextControl txtCtl = dt.control();
txtCtl.bold(7);
dialog.run();
A working example using addFieldValue (similar to Matej's solution):
Dialog dialog = new Dialog("Dialog example");
DialogField f1 = dialog.addFieldValue(extendedTypeStr(String30), 'Value', "Delete this field's value?");
FormBuildStringControl c1 = f1.control();
c1.allowEdit(false);
c1.skip(true);
c1.bold(7);
c1.viewEditMode(ViewEditMode::View);
dialog.run();
I doubt that Dialog class has the ability to display bold text, at least I haven't seen such, neither did I find any method to format text in a dialog. One solution would be to create custom form that looks like a dialog box, but I think it is redundant.
Regarding uppercase, you can use strUpr (link) method:
//other code
dialog.addText(strUpr(strFmt("Delete this field's value: %1?", MyTable.FieldTable)));
//other code

lwuit text area

I developed an RSS Application for two XML files and displayed it on two LWUIT Tabs. The problem is with my LWUIT TextArea, whenever I click on my ListForm (it contains titles from the RssFile), I need to display description information from the RSS File. First time I am able to display the description related to the title clicked in ListForm. If I click the ListForm the next time onwards I am able to display the same description again and again in the textarea..(Eventhough I am getting Related Description from RssFile)
Here is my Code:
private void displayCompleteNewsScreen(News detailNews) {
Label title = new Label(detailNews.getTitle());
form2.setTitleComponent(title);
String Description = detailNews.getDescription();
System.out.println("Description" + Description);//Here i am able to get different Description values Related to myList Screen but in text area it is displaying First one always
big = new TextArea();
big.setEditable(false);
big.setText(Description);
form2.addComponent(pubDate);
form2.addComponent(big);
form2.show();
}
As you are reusing form2 instance you should clear it in displayCompleteNewsScreen method. Call removeAll before calling setTitleComponent.
And don't forget to set form2 Commands again in displayCompleteNewsScreen.

How to align RIGHT the content of TextArea in LWUIT?

I want to align the text in a TextArea to the right. I tried the following code:
Form form = new Form();
TextArea textArea = new TextArea("Some Arabic text ...");
textArea.setRTL(true);
textArea.setAlignment(RIGHT);
form.addComponent(textArea);
The result was just moving the scroll to left,
But the text is still not aligned RIGHT,
check the image below:
So how to align the content to the RIGHT ?
It may sound crazy for the first instance :) but setting the alignment to TextArea.LEFT solved the issue and now it's RIGHT aligned !
Form form = new Form();
TextArea textArea = new TextArea("Some Arabic text ...");
textArea.setRTL(true);
textArea.setAlignment(TextArea.LEFT);
form.addComponent(textArea);
Setting it to LEFT makes the displayed text RIGHT aligned !
Or by removing the textArea.setRTL(true) which is mirroring the display
Form form = new Form();
TextArea textArea = new TextArea("Some Arabic text ...");
textArea.setAlignment(TextArea.RIGHT);
form.addComponent(textArea);
For those who are interested in more complicated details when it's set to RTL:
the paint method of TextArea class is
public void paint(Graphics g) {
UIManager.getInstance().getLookAndFeel().drawTextArea(g, this);
}
And drawTextArea method in DefaultLookAndFeel is as follows:
int align = ta.getAbsoluteAlignment();
// remaining code is here in initial source
switch(align) {
case Component.RIGHT:
x = ta.getX() + ta.getWidth() - rightPadding - f.stringWidth(displayText);
break;
// remaining code is here in initial source
}
g.drawString(displayText, x, y);
Unfortunately TextArea.RIGHT value is 3
But when calling ta.getAbsoluteAlignment() it returns 1 (despite that the object's alignment is set by code to TextArea.RIGHT !!)
Meanwhile TextArea.Left value is 1
That's why it matched the value in the switch and was aligned to RIGHT
BTW, if you set
textArea.setAlignment(Component.RIGHT);
it will also be wrong, because Component.RIGHT outside the paint method has the value 3 not 1 !
You only have to write 'TextArea.RIGHT' instead of 'RIGHT'
textArea.setAlignment(TextArea.RIGHT);
You can use the following line:
TextArea textArea = new TextArea("Some Arabic text ...");
textArea.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

Label does not render the string "0" (Flex 4.5)

I was writing a custom chart component where. To add labels, I create a spark label and add it on screen. Although all other labels rendered, I noticed that the zero label does not render at all. Here's my code:
var invisibleTextField:TextField = new TextField();
var zeroLabel:spark.components.Label = new spark.components.Label();
zeroLabel.text = "0";
zeroLabel.name = "0Label";
invisibleTextField.text = " 0 ";
zeroLabel.width = invisibleTextField.textWidth;
zeroLabel.height = invisibleTextField.textHeight;
addChild(zeroLabel);
After multiple attempts, I figure that the label discards "0" as an empty string. I managed to workaround using spaces before and after the zero. Only one space would also do, but I needed center aligning. Anyone has any idea why this happens?
There's a delay between text is filled into a text field and when it's dimensions are updated. Try using TextExtent instead of an invisible text field to do what you're doing.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextExtent.html

Resources