How to make scroll panel+flex table wrap text correctly?

112 views
Skip to first unread message

chris

unread,
Nov 6, 2009, 8:23:50 AM11/6/09
to Google Web Toolkit
I was wondering if anyone knew how to wrap text like several chat
applications do. I have a ChatArea private class that I am trying to
add to a widget. It works, however if a message to add to the chat
text is 1000 characters with no new lines, the ScrollPanel does not
wrap the text and adds a very long horizontal scroll.

private class ChatPart extends ScrollPanel {

final FlexTable flexTable = new FlexTable();

ChatPart() {
super();
FlexCellFormatter cellFormatter = flexTable.getFlexCellFormatter();
cellFormatter.setColSpan(0,0,2);
flexTable.addStyleName("chat-FlexTable");
flexTable.setWidth("100%");
this.add(flexTable);
this.setWidth("100%");
this.setHeight("300");
}

/**
* Add a message
*/
void addMessage(String user, String message) {
int numRows = flexTable.getRowCount();
flexTable.getFlexCellFormatter().setVerticalAlignment(numRows, 0,
HasVerticalAlignment.ALIGN_TOP);
flexTable.getFlexCellFormatter().setVerticalAlignment(numRows, 1,
HasVerticalAlignment.ALIGN_TOP);
flexTable.getFlexCellFormatter().setWordWrap(numRows, 1, true);

flexTable.setWidget(numRows, 0, ChatApplication.images.greenIcon
().createImage());
flexTable.setWidget(numRows, 1, new HTML("<b>" + user + ":</b>
"+message));
flexTable.getFlexCellFormatter().setRowSpan(0, 1, numRows+1);
this.scrollToBottom();
}
}

chris

unread,
Nov 9, 2009, 10:24:40 AM11/9/09
to Google Web Toolkit
If anyone has any ideas on this, it would be greatly appreciated.

Christian López Espínola

unread,
Nov 9, 2009, 1:00:02 PM11/9/09
to google-we...@googlegroups.com
HTML class has another constructor:
HTML(java.lang.String html, boolean wordWrap)
Try with:
flexTable.setWidget(numRows, 1, new HTML("<b>"
+ user + ":</b>
"+message, true));



>>                         flexTable.getFlexCellFormatter().setRowSpan(0, 1, numRows+1);
>>                         this.scrollToBottom();
>>                 }
>>         }
> >
>



--
Cheers,

Christian López Espínola <penyaskito>
Reply all
Reply to author
Forward
0 new messages