JAVA GWT DialogBox how to add new line char - java

I am having an issue trying to add a new line to a DialogBox. I have tried the normal "\n" and also tried putting my lines inside of HTML style tags. Neither of these attempts worked. Help is appreciated.
DialogBox dialog = new DialogBox();
dialog.setText(" Meter ID:\t\t" + blink.getMeterId() + "\n X coordinate:\t\t" + blink.getXCoord() + "\n Y coordinate:\t\t" + blink
.getYCoord());

Issue resolved via using setHTML to set the contents of the DialogBox
dialog.setHTML("<p> Meter ID: " + blink.getMeterId() + "</p> <p> X coordinate:\t\t" + blink.getXCoord() + "</p> <p> Y coordinate:\t\t" + blink
.getYCoord() + "</p>");
note this is using <p></p> for new paragraph but <br> and other html will work also

just use another \ as an escape character in a string:
new line: \\n
DialogBox dialog = new DialogBox();
dialog.setText(" Meter ID:\\t\\t" + blink.getMeterId() + "\\n X coordinate:\\t\\t" + blink.getXCoord() + "\\n Y coordinate:\\t\\t" + blink
.getYCoord());

Related

I can't set a string in a TextView in an Android app (using Java)

I'm building a simple calculator Android app in Java that will receive 2 numbers as inputs and when the user presses one of the 4 action buttons (+, -, *, /) the exercise and it's solution will appear in the bottom of the screen inside a TextView in this format:
{num1} {action} {num2} = {solution}
I tried to declare a string and form the exercise's string in it and in the end I used "setText" to change the TextView but instead of showing the full exercise when I run the app it shows something like "androidx.appcompat.widget.AppCom".
Here is an example for the string I form when the user clicks on the + button:
exerciseStr = etNum1.toString() + " + " + etNum2.toString() + " = " + String.valueOf(Integer.valueOf(etNum1.getText().toString())+Integer.valueOf(etNum2.getText() + ""));
Does anybody know what the issue may be?
You should call getText() befor calling toString():
exerciseStr = etNum1.getText().toString() + " + " + etNum2.getText().toString() + " = " + String.valueOf(Integer.valueOf(etNum1.getText().toString())+Integer.valueOf(etNum2.getText() + ""));
Change it to like this.
exerciseStr = etNum1.getText().toString() + " + " + etNum2.getText().toString() + " = " + String.valueOf(Integer.valueOf(etNum1.getText().toString())+Integer.valueOf(etNum2.getText() + ""));

Java Centring multiline JLabel Text properly

I need to centre two lines of text in a JLabel. My code is:
lblSolution.setHorizontalAlignment(JLabel.CENTER);
...
lblSolution.setText("<html>" + result.getNearest() + "<br>" + "<br>" + result.getSolutionString() + "</html>");
The problem is, it centres the longer of the two lines, and aligns the shorter at the same x position as the other.
This fixed it:
lblSolution.setText("<html><div style='text-align:center'>" + result.getNearest() + "<br>" + "<br>" + result.getSolutionString() + "</div></html>");

Tooltip using html javafx

I want to add a tooltip on a checkbox of javafx. I want to make it using java code. This tooltip text depends on some object properties. My problem is that i want to have some(not all) words bold inside the tooltip. Is there any way to do it? As far as i googled i didn't found a solution or a way to do it using for example html.
It would be a charm if i could do something like this:
PaggingTest paggingTest = new PaggingTest();
Tooltip tooltip = new Tooltip(
"<b>AlgorithmType:</b> " + paggingTest.getAlgorithmType()
+ "<br/><b>Memory Pages:</b> " + paggingTest.getMemoryPages()
+ "<br/><b>Program Pages:</b> " + paggingTest.getProgramPages()
+ "<br/><b>Sample Count:</b> " + paggingTest.getSampleCount()
+ "<br/><b>Distribution Type:</b> " + paggingTest.getDistributionType());
CheckBox checkBox = new CheckBox("Test");
checkBox.setTooltip(tooltip);
testFlowPane.getChildren().add(checkBox);
You could try this:
WebView web = new WebView();
WebEngine webEngine = web.getEngine();
webEngine.loadContent
(
"<b>AlgorithmType:</b> " + paggingTest.getAlgorithmType()
+ "<br/><b>Memory Pages:</b> " + paggingTest.getMemoryPages()
+ "<br/><b>Program Pages:</b> " + paggingTest.getProgramPages()
+ "<br/><b>Sample Count:</b> " + paggingTest.getSampleCount()
+ "<br/><b>Distribution Type:</b> " + paggingTest.getDistributionType()
);
Tooltip tip = new Tooltip();
tip.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
tip.setGraphic(web);
You may have to apply some css styling to the webview to get it to blend in with your tip.

create tableview using html content in android

I have to develop one android native application using stringbuffer with html content.
Here i have used below code:
PayPalInvoiceItem item1 = new PayPalInvoiceItem();
sb.append("<html><body><table>");
for (int i = 0; i < Constants.mItem_Detail
.size(); i++) {
String title = Constants.mItem_Detail
.get(i).get(
SingleMenuItem.KEY_PNAME);
String qty = Constants.mItem_Detail.get(i)
.get(SingleMenuItem.KEY_QTY);
String cost = Constants.mItem_Detail.get(i)
.get(SingleMenuItem.KEY_PRICE);
String total = Constants.mItem_Detail
.get(i).get(
SingleMenuItem.KEY_TOTAL);
total_count=total_count+Integer.parseInt(qty);
StringBuffer buffer = sb.append("<tr>" + "<td>" + title
+ "</td><td>" + qty + " * " + cost
+ "</td>" + " = <td>" + total
+ " " + "</td></tr>");
item1.setName(buffer.toString());
Now i have to run the application means my output is looking like
<html><body><table>"<tr>" "<td>"krishna
"</td><td>" 1 " * " 100
+ "</td>" = <td>" 100
+ " " + "</td></tr>
But i need the o/p like:
krishna 1 100 100
veni 2 30 60
How can i do????
please help me ???
EDIT:
here i have to change the below line item1.setName(buffer.toString());
to
item.setName(buffer.toString(), "text/html; charset=utf-8"); means am getting following error:
The method setName(String) in the type PayPalInvoiceItem is not applicable for the arguments (String,
String)
How can i resolve these error ????
What is the 'item' you are trying to setName on? by the sounds of things you probably just need to create a WebView like this:
WebView view = new WebView(this);
view.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
view.loadData(stringBuffer.toString(), "text/html", "UTF-8");
setContentView(view);
you also seem to have not terminated the HTML correctly i.e your last write to the StringBuffer should be:
stringBuffer.append("</table></body></html>");
also check your line:
total_count=total_count+Integer.parseInt(qty);
should it not be:
total_count=total_count+Integer.parseInt(total);

Eclipse Java Editor line wrapping not as expected

I have following lines of code that just don't want to be wrapped:
tran = TransactionFactory.generateDoubleEntryTransaction(cAcc, acc, qTran.amount, qTran.date, qTran.memo, qTran.payee, qTran.number);
logger.info("Different currencies, Credit: " + entry.getCreditAmount() + " " + creditCurrency.getSymbol() + " -> " + entry.getDebitAmount() + " " + debitCurrency.getSymbol());
Both lines are 150 respective 190 chars long. In my Code formatting settings the maximum line length is set to 100, the Line wrapping settings for Function Calls are all set to "Wrap when necessary". In the preview pane at least it looks like right. Just it doesn't wrap.
I'm using Eclipse 3.6.2 here.
You have to press CTRL+SHIFT+F

Categories

Resources