Results 1 to 2 of 2
- 02-28-2011, 12:59 AM #1
Member
- Join Date
- Feb 2009
- Posts
- 3
- Rep Power
- 0
JList item text does not truncate when it's HTML
When the String to display in the JList is HTML, the item in the list is not truncated when the String is longer than the cell width of the list.
These are the strings used in the list
Instead of being on 1 line, if the getQuestionTitle() or getQuestionAnswer() are too long this is the result:Java Code:if (hasAnswer() == false){ return "<html><font color=\"gray\"> Unanswered </font>" + getQuestionTitle() + "</html>"; return getQuestionTitle(); } else { return "<html><font color=\"green\"> Answered </font> " + getQuestionTitle() + "<font color=\"green\"> Answer: </font>" + getQuestionAnswer() + "</html>"; return getQuestionTitle() + " " + getQuestionAnswer(); }
Unanswered
This is an example. This is an example. This is an example. This is an example.
and
Answered
This is an example. This is an example. This is an example. This is an example.
Answer:
This is an example. This is an example. This is an example. This is an example.
But I want them on 1 line with "..." shown at the end, not 2 or 4 lines.
When I take out the HTML it truncates as expected, but I need the different coloured text at the beginning.
Thanks
- 03-02-2011, 08:09 PM #2
Member
- Join Date
- Feb 2009
- Posts
- 3
- Rep Power
- 0
fixed it myself with workaround
I used string.substring(fromIndex, toIndex); to truncate it myself
eg:
Java Code:String q = getQuestionTitle(); if (q.length() > 30){ String shortQ = q.substring(0, 30)+"..."; return "<html><font color=\"gray\"> Unanswered </font>" + shortQ +"</html>"; } else { return "<html><font color=\"gray\"> Unanswered </font>" + q + "</html>"; }
Similar Threads
-
Add JList item from resultset
By mine0926 in forum NetBeansReplies: 1Last Post: 06-17-2010, 09:47 AM -
taking data from several textfields and combining them to be one item in a JList
By Ekul in forum New To JavaReplies: 3Last Post: 11-11-2009, 09:00 PM -
problem in displaying text inside the item label - JFREECHART
By chittora in forum Java 2DReplies: 9Last Post: 07-21-2009, 02:41 AM -
How do I display a JList with icons and text?
By aneesahamedaa in forum AWT / SwingReplies: 2Last Post: 09-04-2008, 08:49 AM -
Unsupported Content-Type: text/html Supported ones are: [text/xml]
By luislopezco in forum Advanced JavaReplies: 0Last Post: 05-26-2008, 04:26 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks