enter image description herei want to print all the Double variables in a java label. but when i execute the program only Qty1 print in the label.so that i used escape sequences but the also dont work. Could anyone tell me how to fix this.What i really expect to do is something like in the attachment.
Code
JButton receipt = new JButton("Receipt");
receipt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Double Qty1= Double.parseDouble(textField.getText());
Double Qty2=Double.parseDouble(textField_2.getText());
Double Qty3=Double.parseDouble(textField_3.getText());
lblRecipt.setText("\t\nHotel \n\nManagement System"+Qty1);
// lblRecipt.setText("Hotel Management System"+Qty1);
You can use swing's html formatting feature as explained in https://docs.oracle.com/javase/tutorial/uiswing/components/html.html.
To specify that a component's text has HTML formatting, just put the tag at the beginning of the text, then use any valid HTML in the remainder.
This is what swing example offers:
Your code might look like:
lblRecipt.setText("<html>\t<br>Hotel<br><br>Management System"+Qty1+"</html>");
Related
I've stored a string in the database. When I save and retrieve the string and the result I'm getting is as following:
This is my new object
Testing multiple lines
-- Test 1
-- Test 2
-- Test 3
That is what I get from a println command when I call the save and index methods.
But when I show it on screen. It's being shown like:
This is my object Testing multiple lines -- Test 1 -- Test 2 -- Test 3
Already tried to show it like the following:
${adviceInstance.advice?.encodeAsHTML()}
But still the same thing.
Do I need to replace \n to or something like that? Is there any easier way to show it properly?
Common problems have a variety of solutions
1> could be you that you replace \n with <br>
so either in your controller/service or if you like in gsp:
${adviceInstance.advice?.replace('\n','<br>')}
2> display the content in a read-only textarea
<g:textArea name="something" readonly="true">
${adviceInstance.advice}
</g:textArea>
3> Use the <pre> tag
<pre>
${adviceInstance.advice}
</pre>
4> Use css white-space http://www.w3schools.com/cssref/pr_text_white-space.asp:
<div class="space">
</div>
//css code:
.space {
white-space:pre
}
Also make a note if you have a strict configuration for the storage of such fields that when you submit it via a form, there are additional elements I didn't delve into what it actually was, it may have actually be the return carriages or \r, anyhow explained in comments below. About the good rule to set a setter that trims the element each time it is received. i.e.:
Class Advice {
String advice
static constraints = {
advice(nullable:false, minSize:1, maxSize:255)
}
/*
* In this scenario with a a maxSize value, ensure you
* set your own setter to trim any hidden \r
* that may be posted back as part of the form request
* by end user. Trust me I got to know the hard way.
*/
void setAdvice(String adv) {
advice=adv.trim()
}
}
${raw(adviceInstance.advice?.encodeAsHTML().replace("\n", "<br>"))}
This is how i solve the problem.
Firstly make sure the string contains \n to denote line break.
For example :
String test = "This is first line. \n This is second line";
Then in gsp page use:
${raw(test?.replace("\n", "<br>"))}
The output will be as:
This is first line.
This is second line.
lets say we have some grammar like this.
Model:
greeting+=Greeting*;
Greeting:
'Hello' name=ID '!';
I would like to check whether the text written text in name is a valid text.
All the valid words are saved in an array.
Also the array should be filled with words from a given file.
So is it possible to check this at runtime and maybe also use this words as suggestions.
Thanks
For this purpose you can use a validator.
A simple video tutorial about it can be found here
In your case the function in the validator could look like this:
public static val INVALID_NAME = "greeting_InvalidName"
#Check
def nameIsValid(Greeting grt) {
val name = grt.getName() //or just grt.Name
val validNames = NewArrayList
//add all valid names to this list
if (!validNames.contains(name)) {
val errorMsg = "Name is not valid"
error(errorMsg, GreetingsPackage.eINSTANCE.Greeting_name, INVALID_NAME)
}
}
You might have to replace the "GreetingsPackage" if your DSL isn't named Greetings.
The static String passed to the error-method serves for identification of the error. This gets important when you want to implement Quickfixes which is the second thing you have asked for as they provide the possibility to give the programmer a few ideas how to actually fix this particular problem.
Because I don't have any experience with implementing quickfixes myself I can just give you this as a reference.
Could someone write me how to make a new line in error message in RegexpValidator in Vaadin?
I have method:
public TextField addPhoneNumberField(String value, String location, boolean readOnly) {
final String PATTERN = "^[0][0-9\\s]*$";
final RegexpValidator validator = new RegexpValidator(PATTERN,
"Phone number is not valid. Only numbers are allowed. Phone number must begin with zero");
etc
I need have each sentence in new line. I tried to put there \n, \r\n, <br/>, but nothing is working.
Is it
possible?
Simplest way (without extending Vaadin's client component VErrorMessage) is to use preformated text and use CSS rule for it.
For new line in java use: \n
And add style rule in used style.css file (example for all tooltip error messages):
.v-tooltip .v-errormessage {
white-space: pre;
}
I would like to print a PDF document created with A4 format on a printer that is using US letter paper.
First, my method to print the doc on a printer with A4 format.
public static void printWithPdfBox(String strFilename) throws IOException, PrinterException
{
PrinterJob job = PrinterJob.getPrinterJob();
System.out.println("Printer name : "+ job.getPrintService().getName());
PDDocument doc = new PDDocument();
doc = PDDocument.load(strFilename);
PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
attributes.add(Sides.ONE_SIDED);
job.setPageable(new PDPageable(doc, job));
job.print(attributes);
}
I tried to add this attribute but it is not working :
attributes.add(MediaSizeName.NA_LETTER);
In the help of print method, it is mentionned :
Note that some attributes may be set directly on the PrinterJob by equivalent method calls, (for example), copies: setcopies(int), job name: setJobName(String) and specifying media size and orientation though the PageFormat object.
If someone has a solution, I'll apreciate his help ;o)
For some reasons the line breaks when send SMS from MVC, not working.
I am using code like,
Constants.cs
public struct SmsBody
{
public const string SMSPostResume=
"[ORG_NAME]"+
"[CONTACT_NUMBER]"+
"[ORG_NAME]"+
"[CONTACT_PERSON]"+
"[EMAIL]"+
"[MOBILE_NUMBER]";
}
Then I call these variables at controller like,
SmsHelper.Sendsms(
Constants.SmsSender.UserId,
Constants.SmsSender.Password,
Constants.SmsBody.SMSPostResume
.Replace("[NAME],",candidate.Name)
.Replace("[EMAIL],",candidate.Email) etc......
My Issue is when i get sms these all things are same line. no spacing.
MY OUTPUT
Dearxxxxyyy#gmail.com0000000000[QUALIFICATION][FUNCTION][DESIGNATION][PRESENT_SALARY][LOCATION][DOB][TOTAL_EXPERIENCE][GENDER] like that.
How to give space between these? Anyone know help me...
Putting the string parts on separate lines, and concatenating them is not a line break... The parts will end up exactly after one another. You should try putting a \n (line break escaped sequence) at each place you want a line break:
public const string SMSPostResume=
"[ORG_NAME]\n"+
"[CONTACT_NUMBER]\n"+
"[ORG_NAME]\n"+
"[CONTACT_PERSON]\n"+
"[EMAIL]\n"+
"[MOBILE_NUMBER]\n";
Also a note based on #finman's comment:
Depending on the service it might be \r\n instead of \n though
So you should look up int he API docs which one would work.
Also there is another error: you try to match string constants with a , at their ends, and the original ones don't have that...
SmsHelper.Sendsms(
Constants.SmsSender.UserId,
Constants.SmsSender.Password,
Constants.SmsBody.SMSPostResume
.Replace("[NAME],",candidate.Name) // <- this line!
.Replace("[EMAIL],",candidate.Email) // <- this line!
You should rewrite either the format string to include, or the replaces to exclude the ,:
SmsHelper.Sendsms(
Constants.SmsSender.UserId,
Constants.SmsSender.Password,
Constants.SmsBody.SMSPostResume
.Replace("[NAME]",candidate.Name) // <- no "," this time
.Replace("[EMAIL]",candidate.Email) // <- no "," this time
//...etc
public const string SMSPostResume=
"[ORG_NAME]"+
"\r[CONTACT_NUMBER]"+
"\r[ORG_NAME]"+
"\r[CONTACT_PERSON]"+
"\r[EMAIL]"+
"\r[MOBILE_NUMBER]";
Also, in
Replace("[NAME],",candidate.Name)
are you sure you want the comma after [NAME] ? If it's not in the string, don't try to replace it.