Home » Enterprise Java » gwt » Dynamic FlexTable Example

About Byron Kiourtzoglou

Byron is a master software engineer working in the IT and Telecom domains. He is an applications developer in a wide variety of applications/services. He is currently acting as the team leader and technical architect for a proprietary service creation and integration platform for both the IT and Telecom industries in addition to a in-house big data real-time analytics solution. He is always fascinated by SOA, middleware services and mobile development. Byron is co-founder and Executive Editor at Java Code Geeks.

Dynamic FlexTable Example

With this example we are going to demonstrate how to create a Dynamic FlexTable example using the Google Web Toolkit, that is an open source set of tools that allows web developers to create and maintain complex JavaScript front-end applications in Java. To create a FlexTable example one should perform the following steps:

  • The DynamicFlexTable class implements the com.google.gwt.core.client.EntryPoint interface to allow the class to act as a module entry point. It overrides its onModuleLoad() method.
  • Create a new flexTable.
  • Create a Button for adding new row and a Button for deleting a row.
  • Create a new VerticalPanel. Add the buttons to it.
  • Create a new HorizontalPanel.
  • Add the VerticalPanel and the FlexTable to the HorizontalPanel.
  • Add the HorizontalPanel to the RootPanel, that is the panel to which all other widgets must ultimately be added.

Let’s take a look at the code snippet that follows:

package com.javacodegeeks.snippets.enterprise;

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.user.client.ui.Button;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

public class DynamicFlexTable implements EntryPoint {

	public void onModuleLoad() {
		//Create new Instance of FlexTable
		final FlexTable flexTable = new FlexTable();

  //Set table headers
		flexTable.setText(0, 0, "N/A");

  flexTable.setText(0, 1, "Column 1");
		flexTable.setText(0, 2, "Column 2");

		//Button for adding new row
		Button AddRowButton = new Button("Add Row", new ClickHandler() {
			public void onClick(ClickEvent event) {

		//Button for deleting row
		Button DeleteRowButton = new Button("Delete Row", new ClickHandler() {
			public void onClick(ClickEvent event) {
		VerticalPanel buttonsPanel = new VerticalPanel();
		HorizontalPanel hp = new HorizontalPanel();

	// Add row method
	private void addRow(FlexTable flexTable) {
		int numRows = flexTable.getRowCount();
		flexTable.setText(numRows, 0, "Row "+ numRows);
		flexTable.setText(numRows, 1, "Item["+ numRows +", 1]");
		flexTable.setText(numRows, 2, "Item["+ numRows +", 2]");

	// Delete row method
	private void deleteRow(FlexTable flexTable) {
		int numRows = flexTable.getRowCount();
		if (numRows > 1) {
			flexTable.removeRow(numRows - 1);

This was an example of how to create a Dynamic FlexTable example using the Google Web Toolkit.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!


1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design


and many more ....


Receive Java & Developer job alerts in your Area

I have read and agree to the terms & conditions


Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments