View RSS Feed

Java Swing

JTable Introduction

Rate this Entry
by , 04-26-2012 at 08:42 PM (1278 Views)
Many facilities are present in a JTable which makes the rendering and editing possible. But defaults are also provided for such features hence to setup the tables very easily. For instance, a table could be setup with 10 columns and 10 rows of numbers.
Java Code:
      TableModel dataModel = new AbstractTableModel() {
          public int getColumnCount() { return 10; }
          public int getRowCount() { return 10;}
          public Object getValueAt(int row, int col) { return new Integer(row*col); }
      };
      JTable table = new JTable(dataModel);
      JScrollPane scrollpane = new JScrollPane(table);
Applications which use JTable, they shall be designed in such a way that a special kind of attention is being given to the structures of data which present the data present in a table. DefaultTableModel is considered to be a model implementation which use “vector of vector” of objects so that cell values could be stored. Also data copied from application to the DefaultTableModel, data could be wrapped in TableModel interface so that data might be sent directly to the JTable. Often it would be resulting in much more efficient applications as models are given free hand to make choice of the internal presentation of the data. Rule of thumb to decide the usage of the DefaultTableModel or AbstractTableModel is using AbstractTableModel for creation of subclass and other one when subclasses are not needed.

Submit "JTable Introduction" to Facebook Submit "JTable Introduction" to Digg Submit "JTable Introduction" to del.icio.us Submit "JTable Introduction" to StumbleUpon Submit "JTable Introduction" to Google

Categories
JTable

Comments