I have a question. I have a queue and I want to show it in JLabel text, but I dont know how put the complete data from the queue in just one JLabel, I mean. I know the method JLabel.setText(), but each time I show a new data from the queue the JLabel refresh and then the data that I put before of that dissapear, and I want to show the complete Queue in a JLabel spacing the data, like this but in a JLabel...
for(int i=0;i<Queue.length;i++);{
{ System.out.print(Queue.push()+" ");}
and my problem is when I try to show the another data pushing the Queue, the JLabel refresh the text...
for(int i=0;i<Queue.length;i++);{
{ JLabel.setText(Queue.push()+" ");}
there is a method to show it correctly? thank you!.
You need to collect all values in a string variable and then set it.
String text = "";
for(int i=0;i<Queue.length;i++){
text += Queue.push()+" ";
}
JLabel.setText(text.trim());
Probably it would be better to show it as HTML. So you can make the line-break
String text = "<html>";
for(int i=0;i<Queue.length;i++){
text += Queue.push()+"<br>";
}
text += "</html>"
JLabel.setText(text);
You have to add the text to the existing text:
for(int i=0;i<Queue.length;i++){
JLabel.setText(JLabel.getText() + Queue.push()+ " ");
}
Or you can store the data and set it to the JLabel at the end:
String s = "";
for(int i=0;i<Queue.length;i++){
s = (s + Queue.push() + " ")
}
JLabel.setText(s);
Hope it helps.
Related
I have a JList in which I am formatting the text before it is added to the JList cell using HTML. I'm doing this because I'm lazy and don't want to get complex with a cellRenderer. I only need 2 separate lines in each JList cell so HTML just seemed quicker and easier for such a simple requirement, however when I run this it correctly formats it, however, the text does not start on the edge of the button. I'm assuming this is because the HTML takes up space in whitespaces in which case I assume I can't fix that?
public static void receiveDataEmailList(String data) {
Scanner scLine = new Scanner(data).useDelimiter("&");
int num = scLine.nextInt();
String[] emails = new String[num];
for (int i = 0; i < num; i++) {
emails[i] = "" + "<html><ul style=\"list-style-type:none;\"><li style=\"font-size:10px\">" + scLine.next() + "</li><li style=\"font-size:8px\">" + "Subject: " + "Hello" + "</li></ul></html>";
}
EmailList.setListOfEmails(emails);
}
public void itemStateChanged(ItemEvent e)
{
text += "Language : ";
text += "Hindi: " + Hindi.getState();
text += " English: " + English.getState();
text += "Maths: " + Maths.getState();
label.setText("");
label.setText(text);
}
this code show new result with previous one i want updated result only not the previous one so how can i remove previous AWT label output from the frame.
just remove the + in the first line of the method.
text = "Language : ";
Please note that the way you are appending Strings is not efficient. Try using String.format() instead.
I am trying to read emails using Java. I got the in-box mails correctly.
But the problem is text body is shown in line by line. I need the body text as it is shown in mail,ie output text should be in same order (rephrasing proposal: "tabular alignment") as shown in mail.
This is the code I used to get body text from Message object,
private static String getTextFromMessage(Message message) throws MessagingException, IOException
{
String result = "";
if (message.isMimeType("text/plain"))
{
result = message.getContent().toString();
}
else if (message.isMimeType("multipart/*"))
{
MimeMultipart mimeMultipart = (MimeMultipart) message.getContent();
result = getTextFromMimeMultipart(mimeMultipart);
}
return result;
}
private static String getTextFromMimeMultipart(MimeMultipart mimeMultipart) throws MessagingException, IOException
{
String result = "";
int count = mimeMultipart.getCount();
for (int i = 0; i < count; i++)
{
BodyPart bodyPart = mimeMultipart.getBodyPart(i);
if (bodyPart.isMimeType("text/plain"))
{
result = result + "\n" + bodyPart.getContent();
break;
}
else if (bodyPart.isMimeType("text/html"))
{
String html = (String) bodyPart.getContent();
result = result + "\n" + org.jsoup.Jsoup.parse(html).text();
}
else if (bodyPart.getContent() instanceof MimeMultipart)
{
result = result + getTextFromMimeMultipart((MimeMultipart) bodyPart.getContent());
}
}
return result;
}
For example, this is the mail content:
.
I need output as,
Beschreibung Stückpreis Anzahl Betrag
22545047 106,56 EUR 1 €106,56 EUR
as it as shown in mail.
But I got the output,
Beschreibung
Stückpreis
Anzahl
Betrag
22545047
106,56 EUR
1
€106,56 EUR
Can anyone please help me to solve this issue.
Thanks in advance
By the way, the strange words are German for "description", "price per piece", "number of pieces", "total price for this kind". I.e. they form a bill and are irrelevant for the problem.
It seems that you do not like the newlines which you explicitly insert in some of your "rendering" methods.
In order to get rid of them, delete all occurrences of
+ "\n"
in your code.
Then consider adding a single + "\n" at the end of the output.
In case the text your are outputting is the result of a html->plain text conversion, you lose the tabular alignment created by the html rendering. There are no "ten spaces". In order to get the alignment information translated into ascii-art (spaces to align columns) you'd have to do some intense analysis of the html markup and derive an appropriate number of spaces to insert.
In my program, I have an add button and add button to add the whole citation to an array.
String citeString;
citeString = "";
citeString = lastNameInput.getText()+", "+firstNameInput.getText()+",``"+titleInput.getText()+", "+EditionInput.getText()+", "+PublisherInput.getText()+", "+placePublicationInput.getText()+", "+yearPublicationInput.getText()+".";
Collections.addAll(Citation,citeString);
Collections.sort(Citation, String.CASE_INSENSITIVE_ORDER);
I also have a display button to display the citation to text field
String outString = "";
Collections.sort(Citation, String.CASE_INSENSITIVE_ORDER);
for(int e=0;e<Citation.size();e++){
outString = outString+Citation.get(e)+"\n";
}
citeOutput.setText(outString);
I need to italicize the titleInput. How do I do that?
I need to insert data from my parsed XML file to mySQL table. Problem is that I have few attributes and don't know how to insert them in one row. I tried with updateString but it writes only last attribute.
Here is example from XML file:
<Tr rn=\"999999999999999\" vr=\"T\" sSpre=\"S\" reg=\"P\" dSpre=\"2010-09-30\" dOdprt=\"2000-01-01\" iban=\"SI56\" eno=\"R\" vir=\"R\" maticnaPps=\"00000000\"><Imetnik davcna=\"0000000\" matSub=\"0000000\" drz=\"705\"><PopolnoIme>xxx</PopolnoIme><KratkoIme>xxx</KratkoIme><Naslov sifTipNaslova=\"01\" sifObcina=\"039\" sifPosta=\"1303\" sifUlica=\"0000\" sifNaselje=\"059\" stHisna=\"027\" sifHsmid=\"11694551\"><Obcina>xxx</Obcina><Posta>xxx</Posta><Ulica>xxx</Ulica><Naselje>xxx</Naselje></Naslov></Imetnik></Tr>
This is scratch from my java program that I used for writing in mySQL table.
if (myWorkLine.substring(0,4).equals(Tr)) {
uprs.afterLast();
uprs.moveToInsertRow();
if (myWorkLine.contains(Tr)) {
myWorkLine = myWorkLine.substring(myWorkLine.indexOf(Tr)+4);
while (!myWorkLine.substring(0,1).equals("<")) {
myTag = myWorkLine.substring(0,myWorkLine.indexOf("="));
myWorkLine = myWorkLine.substring(myWorkLine.indexOf("=")+2);
myValue = myWorkLine.substring(0,myWorkLine.indexOf("\""));
myWorkLine = myWorkLine.substring(myWorkLine.indexOf("\"")+2);
uprs.updateString("Tr",myTag + " " + myValue);
if (myWorkLine.substring(0,myWorkLine.indexOf("\">")).indexOf(">") > 0)
break;
}
}
So once again, I need that in MySQL table column Tr contains attributes rn value, vr value, sSpre value,...
Thanks in advance.
P.S.: Please don't ask why I'm parsing XML file by this method, I had to do it that way. :)
Your code will repeatedly replace the "Tr" column with your concatenation of tag + " " + value so it'll only be the last one that goes in. Don't you perhaps want the different tags to go in different columns? Or maybe you need to continue concatenating and only call updateString at the end.
Could you post the desired table row for the given XML? That should help in determining what you are trying to achieve.
For example, if you just want to append them:
StringBuffer tr = new StringBuffer();
while (!myWorkLine.substring(0,1).equals("<")) {
myTag = myWorkLine.substring(0,myWorkLine.indexOf("="));
myWorkLine = myWorkLine.substring(myWorkLine.indexOf("=")+2);
myValue = myWorkLine.substring(0,myWorkLine.indexOf("\""));
myWorkLine = myWorkLine.substring(myWorkLine.indexOf("\"")+2);
tr.append(myTag + " " + myValue).append(",");
if (myWorkLine.substring(0,myWorkLine.indexOf("\">")).indexOf(">") > 0)
break;
}
if (tr.length() > 0) {
tr.deleteCharAt(tr.length()-1); // get rid of last comma
}
uprs.updateString("Tr",tr.toString());