Note that there are some explanatory texts on larger screens.

plurals
  1. POGWT: adding Image with handler to Table Header
    primarykey
    data
    text
    <p>I've got some problems with CellTable in GWT.</p> <p>What I want to do: I've got CellTable and I want to add header with an image and add action to it. But it doesn't work in my code.</p> <p>My code (all):</p> <pre><code>import java.util.Arrays; import java.util.List; import com.google.gwt.cell.client.Cell; import com.google.gwt.cell.client.ClickableTextCell; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.safehtml.shared.SafeHtmlBuilder; import com.google.gwt.safehtml.shared.SafeHtmlUtils; import com.google.gwt.user.cellview.client.CellTable; import com.google.gwt.user.cellview.client.Header; import com.google.gwt.user.cellview.client.TextColumn; import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.VerticalPanel;` public class HelloGWT implements EntryPoint { public void onModuleLoad() { RootPanel.get().add(new MyTable()); } } class Contact { public Contact(String name, int number) { this.number = number; this.name = name; } public String name; public int number; } class MyTable extends VerticalPanel { public List&lt;Contact&gt; list = Arrays.asList(new Contact("contact_1", 1), new Contact("contact_2", 2), new Contact("contact_3", 3) ); public MyTable() { CellTable&lt;Contact&gt; table = new CellTable&lt;Contact&gt;(); table.addColumn(new MyColumn(), new MyHeader(new ClickableTextCell(), "MyHeader!")); table.setRowData(0, list); this.add(table); } } class MyColumn extends TextColumn&lt;Contact&gt; { public MyColumn() { } @Override public String getValue(Contact object) { // TODO Auto-generated method stub return object.name; } } class MyHeader extends Header&lt;String&gt; { private String columnName; private Image image = new Image("http://www.google.com/mobile/images/mgc3/google-mobile-app48.png"); public MyHeader(Cell&lt;String&gt; cell, String columnName) { super(cell); // TODO Auto-generated constructor stub this.columnName = columnName; image.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { System.out.println("Click!"); } } ); } @Override public String getValue() { // TODO Auto-generated method stub return columnName; } @Override public void render(Cell.Context context, SafeHtmlBuilder sb) { StringBuilder s = new StringBuilder(); s.append(columnName); image.setSize("20px", "20px"); s.append(image); sb.append(SafeHtmlUtils.fromSafeConstant(s.toString())); } } </code></pre> <p>Thanks for any ideas...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload