views:

953

answers:

3

I'm using GWT 1.6.

I am creating a panel that contains a Button and a Label, which I then add to a FlexTable as one of its cells.

The Button is not receiving any Click events. I see that the table supports determining which Cell is clicked on, but in this case, I want the Mouse events to propagate to the various widgets inside the cell. Any idea on how to do that?

+1  A: 

Yeah, I hit that, too - no widgets in the table will receive events. I ended up using code like this:


FixedWidthGrid dataTable = createDataTable();
...
dataTable.addTableListener(new TableListener() {

    public void onCellClicked(SourcesTableEvents sender, int row, int cell) {
        storyViewer.showStory(table.getRowValue(row));
    }

});

You could probably start with something like that, then programmatically send events to your button widget to make the appearance of clicking.

Don Branson
Ultimately there will be more than one clickable widget in the cell. What I am trying to implement is a table header, that has a button to sort and another button to set a filter. So I have to know which of the Widgets the user was actually clicking on within the cell.
mjeffw
Hmmm. So, you'll need to know the location of the click. Not sure that's there - it might be. BTW - are you using a FixedWidthGrid? It has support for sorting.
Don Branson
I've never seen a FixedWidthGrid -- I assume its in some third-party library?
mjeffw
It's from gwt-incubator. Sorry, I just realized you said you're using FlexTable. Try adding a clickhandler, then debug to see what you get in the event. Maybe there's something useful there.
Don Branson
I have to say I'm using anchors, images, and markers (gwt-google-maps) in a FlexTable and they have no problems getting events. Either the listeners aren't being added correctly to the widgets or something is erroneously canceling propagation.
angryundead
A: 

If you know how big your table will be use a Grid instead. All of your widgets will receive there events. I have done this and created my own sortable table.

Carnell
Also one other thing. Where does it state that widgets within a FlexTable will not receive events? Maybe your not adding handlers for your widgets?
Carnell
A: 

You have to subclass the Button google Class and add a constructor with two additional arguments (int col, int row). e.g.

public class RuleButton extends Button {

 private int row;
 private int col;

 public RuleButton(String html, ClickListener listener, int row, int col) {
  super(html, listener);
  setRow(row);
                setCol(col);
 }
        // getters and setters for row and col attributes.
}

When adding the button, call this constructor and pass row and col indexes to it.

Amine