flextable的对应删除

com.google.gwt.user.client.ui.FlexTable

A flexible table that creates cells on demand. It can be jagged (that is, each row can contain a different number of cells) and individual cells can be set to span multiple rows or columns.

可以往 flexible 中加入String 或 Widget ,

setText(int row, int column, String text);

setWidget(int row, int column, Widget widget)

删除

removeRow(int row)

getRowCount() //Gets the number of rows.

//start

package com.bnu.client;

import java.util.ArrayList;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

/** * Entry point classes define <code>onModuleLoad()</code>. */
public class yjy implements EntryPoint {

  /** * This is the entry point method. */
 private VerticalPanel mainPanel = new VerticalPanel();
 private FlexTable stock = new FlexTable();
 private HorizontalPanel addPanel = new HorizontalPanel();
 private TextBox txt = new TextBox();
 private Button addbutton = new Button("Add");
 private Label lab= new Label("");
 private ArrayList<String> stockList = new ArrayList<String>();
 private int currow;
  public void onModuleLoad() {
   stock.setText(0, 0, "name");
   stock.setText(0, 4, "remove");
   currow = stock.getRowCount();
  // Window.alert(""+currow);
   addPanel.add(txt);
   addPanel.add(addbutton);
   mainPanel.add(stock);
   mainPanel.add(addPanel);
   mainPanel.add(lab);
   addbutton.addClickListener(new ClickListener()
   {
  public void onClick(Widget sender) {
   // TODO Auto-generated method stub
   final String str = txt.getText().trim();
   if (!stockList.contains(str))
   {
    stockList.add(str);
    stock.setText(currow, 0, str);
    Button cross = new Button("X");
    cross.addClickListener(new ClickListener()
    {
     //@Override
     public void onClick(Widget sender) {
      // TODO Auto-generated method stub
      int reind = stockList.indexOf(str);
      stockList.remove(reind);
     // Window.alert(reind+"");
      stock.removeRow(reind+1);
      currow=stock.getRowCount();
     }
    });
    stock.setWidget(currow, 4,cross );
    txt.setText("");
    currow = stock.getRowCount();
    txt.setFocus(true);
   }
  }
   });
   RootPanel.get().add(mainPanel);
   txt.setFocus(true);
  }
}

你可能感兴趣的:(UI,Google,gwt)