onBrowserEvent change Cell colour

48 views
Skip to first unread message

Sam Wootton

unread,
Mar 12, 2016, 2:23:23 PM3/12/16
to GWT Users
Dear GWT Users,

Thanks in advance for help.  Ive searched the mail archives and had a good google, but cant find what im after.

I'd like to change the colour of my Cell when the user rolls over it.  I thought it would be as simple as saving a class level / scope variable of SafeHtmlBuilder (when redner is called) and appending to it when onBrowserEvent is executed - but that doesnt seem to work.

public void onBrowserEvent(Context context, Element parent, Track value, NativeEvent event, ValueUpdater<Track> valueUpdater) {

super.onBrowserEvent(context, parent, value, event, valueUpdater);
if("mouseover".equals(event.getType())) {
// change colour



public void render(Context context, Track track, SafeHtmlBuilder safeHtmlBuilder) {
if (track != null) {
safeHtmlBuilder.append(template.showTrack("images/someImg.png",track.getName()));
}
}

Regards, Sam


Gilberto

unread,
Mar 13, 2016, 7:49:52 PM3/13/16
to GWT Users
You just want to change the color on mouse over or need something else?

I ask that because if the problem is only about changing the color of the cell, you can do that with plain CSS.

Something like that:

Java code:
yourTable.addStyleName("myNiceTable");

CSS:

.myNiceTable td:hover {
    color: red; /* or something else */
}

Generally speaking, developers usually change the background color of the hovered table row. For that, you can use a similar CSS:

.myNiceTable tr:hover {
    background-color: #f2f2f2;
}

Hope that helps ;-)

Sam Wootton

unread,
Mar 14, 2016, 5:21:36 AM3/14/16
to google-we...@googlegroups.com
Indeed it does help Gilerto.  I'm indebted, thank you.  You can see I "think in Java" mode (not being a 'web developer') - missed the obvious, apologies.

Although my Cell looks like
interface Template extends SafeHtmlTemplates {
@Template("<table>" +
"<tr height=4px>" +
"<td><img src=\"{0}\"/ height='20' width='20'></td>" +
"<td>{1}</td>" +
"</tr>" +
"</table>")
SafeHtml showTrack(String Image, String name);
}

...and what I wanted was the whole row to be highlighted, but right now it just highlights the background of the text area (not the whole cell browser cell)

Regards Sam

--
You received this message because you are subscribed to a topic in the Google Groups "GWT Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-web-toolkit/Hrn-Wv7imSo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-web-tool...@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages