Tuesday, October 11, 2011

Things to know about JTable

You might already be using JTables comes with Swing in Java but sometimes may not know theses facts, Here's an some facts about JTables.



  • JTable does not contain or cache data; it is simply a view of your data.
  • There are two JTable constructors that directly accept data (SimpleTableDemo uses the first):
    • JTable(Object[][] rowData, Object[] columnNames)
    • JTable(Vector rowData, Vector columnNames)
  • However, these constructors also have disadvantages: 
    • They automatically make every cell editable.
    • They treat all data types the same (as strings).
    • They require that you put all of the table's data in an array or vector, which may not be appropriate for some data. 
  • When adding a JTable use a JScrollpane
    • JScrollPane scrollPane = new JScrollPane(table);
      table.setFillsViewportHeight(true);
  • JTable uses a very simple concept of selection, managed as an intersection of rows and columns. It was not designed to handle fully independent cell selections.

No comments:

Post a Comment