Skip to content

mclamee/AnnotationTableModel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AnnotationTableModel

This is a customizable generic table model class which can be used to convert a POJO to a JTable with the aid of annotations.

##Example Senario:

There are serveral domain classes (Customer, Order, etc) which should be represented as tables in a java swing application. In general case, a table model has to be written for each table/domain class. With the generic table model class, all the domain classes could be turned to tables only by adding simple annotaions to the domain classes, as shown below.

package com.swing.example.domain;

import com.swing.table.ColumnName;

public class Customer {

	@ColumnName(i18nKey = "Customer ID")
	private int id;
	@ColumnName(i18nKey = "Customer Name")
	private String name;
	@ColumnName(i18nKey = "Contact Number")
	private String contact;
	@ColumnName(i18nKey = "Email")
	private String email;

	public Customer(int id, String name, String contact) {
		super();
		this.id = id;
		this.name = name;
		this.contact = contact;
	}

	public Customer() {

	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getContact() {
		return contact;
	}

	public void setContact(String contact) {
		this.contact = contact;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getEmail() {
		return email;
	}


}

The table will look like the one below:

##Example Usage:

GenericTableModel<Customer> customerTableModel = new GenericTableModel<Customer>(new Customer());
JTable tblCustomer = new JTable(customerTableModel);

A working example is included in the src.

About

The Swing Table Model Using POJO with Annotations

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages