INTRODUCTION

Get SimpleTable at SourceForge.net. Fast, secure and Free Open Source software downloads

SimpleTable is a part of the ongoing effort in developing components based on EMC Framework (emc-framework.sourceforge.net). SimpleTable was designed using Java JTable Swing Component which makes development and customization a breeze. It auto generates the columns from the given entity. The component allows dynamic rendering of columns based on the classes supplied as annotated attribute parameters. The entire component follows Model Driven Architecture guidelines and was modeled using Enterprise Architect.

Download Files SimpleTable-1.0

JAR      DOC     SRC

TUTORIAL
  1. Create Entity Object
  2. users table

  3. Create Simple Table by passing Entity as parameter in the Constructor
  4. SimpleTable simpleTable = new SimpleTable(new Users());
    contentPane.add(simpleTable, "Center");

    Add Dummy Users
    simpleTable.AddRow(new Users("Anna", "anna+christalign.com", "Christalign Innovative Solutions Pvt. Ltd.", "CEO", "+91 471 2384497"));
    simpleTable.AddRow(new Users("Ruben", "ruben_gerad+christalign.com", "Christalign Innovative Solutions Pvt. Ltd.", "CTO", "+91 471 2384497"));
    simpleTable.AddRow(new Users("Rubeela", "rubeela+christalign.com", "Christalign Innovative Solutions Pvt. Ltd.", "HR", "+91 471 2384497"));

    SimpleTable Basic

  5. Now Resize columns and add a background image

    private ImageIcon imgBackground = new ImageIcon(com.christalign.emc.tutorial.SimpleTableTutorial.class.getResource("resources/background.jpg"));

    Set Table Properties
    simpleTable.setTableResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
    simpleTable.setBackground(imgBackground);

    table with background

  6. Add Header Image
  7. private ImageIcon imgBackground = new ImageIcon(com.christalign.emc.tutorial.SimpleTableTutorial.class.getResource("resources/background.jpg"));
    private ImageIcon imgDesignation = new ImageIcon(com.christalign.emc.tutorial.SimpleTableTutorial.class.getResource("resources/designation.jpg"));

    Set Table Properties
    simpleTable.setTableResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
    simpleTable.setBackground(imgBackground);
    simpleTable.setColumnHeader("Designation", 72, imgDesignation );

    table with simple header

    Fails to resize header image and render column correctly

    Designation field has no background filling so there is space between designation and phone columns.

    table header image fails to resize

  8. Use Header with background image

    private ImageIcon imgBackground = new ImageIcon(com.christalign.emc.tutorial.SimpleTableTutorial.class.getResource("resources/background.jpg"));
    private ImageIcon imgDesignation = new ImageIcon(com.christalign.emc.tutorial.SimpleTableTutorial.class.getResource("resources/designation.jpg"));
    private ImageIcon imgName = new ImageIcon(com.christalign.emc.tutorial.SimpleTableTutorial.class.getResource("resources/name.jpg"));
    private ImageIcon imgEmail = new ImageIcon(com.christalign.emc.tutorial.SimpleTableTutorial.class.getResource("resources/email.jpg"));
    private ImageIcon imgDesignation = new ImageIcon(com.christalign.emc.tutorial.SimpleTableTutorial.class.getResource("resources/designation.jpg"));
    private ImageIcon imgCompany = new ImageIcon(com.christalign.emc.tutorial.SimpleTableTutorial.class.getResource("resources/company.jpg"));
    private ImageIcon imgPhone = new ImageIcon(com.christalign.emc.tutorial.SimpleTableTutorial.class.getResource("resources/phone.jpg"));
    private ImageIcon imgHDBG = new ImageIcon(com.christalign.emc.tutorial.SimpleTableTutorial.class.getResource("resources/hdbg.jpg"));

    Set Table Properties
    simpleTable.setTableResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
    simpleTable.setBackground(imgBackground);
    simpleTable.setColumnHeader("Name", 100, imgName, false, imgHDBG, imgHDBG, imgHDBG );
    simpleTable.setColumnHeader("Email", 170, imgEmail, false, imgHDBG, imgHDBG, imgHDBG );
    simpleTable.setColumnHeader("Designation", 100, imgDesignation, false, imgHDBG, imgHDBG, imgHDBG );
    simpleTable.setColumnHeader("Company", 250, imgCompany, false, imgHDBG, imgHDBG, imgHDBG );
    simpleTable.setColumnHeader("Phone", 100, imgPhone, false, imgHDBG, imgHDBG, imgHDBG );

    table with dynamic header

  9. Use Header with background image, left and right border images.
  10. private ImageIcon imgBackground = new ImageIcon(com.christalign.emc.tutorial.SimpleTableTutorial.class.getResource("resources/background.jpg"));
    private ImageIcon imgName = new ImageIcon(com.christalign.emc.tutorial.SimpleTableTutorial.class.getResource("resources/name.jpg"));
    private ImageIcon imgEmail = new ImageIcon(com.christalign.emc.tutorial.SimpleTableTutorial.class.getResource("resources/email.jpg"));
    private ImageIcon imgDesignation = new ImageIcon(com.christalign.emc.tutorial.SimpleTableTutorial.class.getResource("resources/designation.jpg"));
    private ImageIcon imgCompany = new ImageIcon(com.christalign.emc.tutorial.SimpleTableTutorial.class.getResource("resources/company.jpg"));
    private ImageIcon imgPhone = new ImageIcon(com.christalign.emc.tutorial.SimpleTableTutorial.class.getResource("resources/phone.jpg"));
    private ImageIcon imgHDBG = new ImageIcon(com.christalign.emc.tutorial.SimpleTableTutorial.class.getResource("resources/hdbg.jpg"));
    private ImageIcon imgHDLeftBG = new ImageIcon(com.christalign.emc.tutorial.SimpleTableTutorial.class.getResource("resources/leftbg.jpg"));
    private ImageIcon imgHDRightBG = new ImageIcon(com.christalign.emc.tutorial.SimpleTableTutorial.class.getResource("resources/rightbg.jpg"));

    Set Table Properties
    //simpleTable.setTableResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); //Disable to use scroll bar.
    simpleTable.setBackground(imgBackground);
    simpleTable.setColumnHeader("Name", 100, imgName, false, imgHDBG, imgHDLeftBG, imgHDRightBG );
    simpleTable.setColumnHeader("Email", 170, imgEmail, false, imgHDBG, imgHDLeftBG, imgHDRightBG );
    simpleTable.setColumnHeader("Designation", 100, imgDesignation, false, imgHDBG, imgHDLeftBG, imgHDRightBG );
    simpleTable.setColumnHeader("Company", 250, imgCompany, false, imgHDBG, imgHDLeftBG, imgHDRightBG );
    simpleTable.setColumnHeader("Phone", 100, imgPhone, false, imgHDBG, imgHDLeftBG, imgHDRightBG );

    Additional Properties
    CENTER IMAGE HEADERS
    simpleTable.setColumnHeader("Name", 100, imgName, true, imgHDBG, imgHDLeftBG, imgHDRightBG );
    simpleTable.setColumnHeader("Email", 175, imgEmail, true, imgHDBG, imgHDLeftBG, imgHDRightBG );
    simpleTable.setColumnHeader("Company", 250, imgCompany, true, imgHDBG, imgHDLeftBG, imgHDRightBG );
    simpleTable.setColumnHeader("Phone", 100, imgPhone, true , imgHDBG, imgHDLeftBG, imgHDRightBG );

    INCREASE ROW HEIGHT
    simpleTable.setRowHeight(35);
    CHANGE GRID COLOR
    simpleTable.setGridColor(Color.LIGHT_GRAY);
    ENABLE MOUSE SCROLLING
    simpleTable.setWheelScrollingEnabled(true);
    SINGLE SELECTION MODE
    simpleTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    simple table customized

  11. Adding Listeners

    simpleTable.getSelectionModel().addListSelectionListener(new ListSelectionListener()
    {
    public void valueChanged(ListSelectionEvent e) {
    if(e.getValueIsAdjusting())
    return;
    ListSelectionModel rowSM = (ListSelectionModel)e.getSource();
    simpleTable.setCurrentRow(rowSM.getMinSelectionIndex());
    }
    });

  12. CRUD Operations

    ADD Operation

    simpleTable.AddRow(new Users("USER", "USER+XYZ.COM", "XYZ CORP","DGM", "33-070777"));

    UPDATE Operation

    simpleTable.UpdateRow(0, new Users("Anna", "anna+christalign.com", "Christalign Innovative Solutions Pvt. Ltd.", "CEO", "+91 9747007078"));

    DELETE Operation

    simpleTable.DeleteRow(2);

    LIST Operation

    for(int i=0; i<simpleTable.getRowCount(); i++){
    Users user = (Users) simpleTable.getRow(i);
    System.out.println(user.getName());
    System.out.println(user.getEmail());
    System.out.println(user.getCompany());
    System.out.println(user.getDesignation());
    System.out.println(user.getPhone());
    }

Annotated Entities

Using RendererClass Property

Add two attributes Director and Photo to User Entity Class.

@EMC(RendererClass="com.christalign.emc.swing.CheckBoxRenderer")
private boolean Director;
@EMC(RendererClass="com.christalign.emc.swing.ImageRenderer")
private URL Photo;
private String Name;
private String Email;
private String Company;
private String Designation;
private String Phone;

// private Image Photo >> ImageIcon.getImage() // private String Photo >> ("C:\\photo.jpg" )

The two classes CheckBox Renderer which accepts boolean type and ImageRenderer which accepts the URL, String filepath, or Image type input classes belongs to DefaultTableCellRenderer class. Your custom class could also be supplied instead but must extend the standard TabelCellRenderer class.

anotated table enitity

SimpleTable in Projects

Webcam

webcam

Submit your projects : info at christalign.com

    Christalign Innovative Solutions Pvt. Ltd.
    http://www.christalign.com
    Copyright 2006-2009. All Rights Reserved.