PDA

View Full Version : How to select text in Html?



Atum
27 Jan 2010, 5:16 AM
public void onModuleLoad() {

final Html allText = new Html();
String date_format = "dd.MM.y HH:mm:ss";
DateTimeFormat df = DateTimeFormat.getFormat(date_format);
StringBuilder sb = new StringBuilder();

for (int i = 0; i < 20; i++) {
String data = df.format(new Date());
// &lt;b&gt;
sb.append("<span id=\"myid" + i + "\" style= \" font-weight: bold;\" >" +
" User Name" + i + "</span>");
sb.append("<br>");
sb.append(data);
sb.append("<br>");

sb.append(" simlle text simple text simple text simple text simple text");
sb.append("<br><br>");
}

allText.setStyleAttribute("overflow", "auto");
allText.setHtml(sb.toString());
allText.setBorders(true);
allText.setSize(200, 150);
RootPanel.get().add(allText);

RootPanel.get().add( new Button("set", new SelectionListener<ButtonEvent>() {

@Override
public void componentSelected(ButtonEvent ce) {

//select id = myid18
// allText ???
}

}));
}



How to select text (user name ) in Html (id = myid18 ) and move to Element scroll position ?

Atum
28 Jan 2010, 11:52 PM
jump to code

String id = "#myid18";

native method


private native void selectText(String id,boolean ie) /*-{
if(!ie)
{
$wnd.location.hash="";
}
$wnd.location.hash=id;
}-*/;
how to select text?

Arno.Nyhm
29 Jan 2010, 12:58 PM
why you not use a grid or a listview for this?