0

the size of table limit is set as static limit and i want to change that to dynamic

here jtable & object declared.

    public  JTable issuetable = null;   
    static Object[][] data;

here is my jtable

public  JTable getIssues() {
    issuetable = new JTable();


    String[] colName = {"Member", "Book", "Issue Date", "Return Date ",
            "Remarks" };
    List<Issue>issues=ServiceFactory.getIssueServiceImpl().findAllIssue();

the size of issuedata is limited to 100000 .. i want to change the limit to dynamic..

    data=new Object[issues.size()][100000];

    for(Issue issue:issues){

        data[i][0]=issue.getMemberId().getName();
        data[i][1]=issue.getBookId().getName();
        data[i][2]=issue.getIssueDate();
        data[i][3]=issue.getReturnDate();
        data[i][4]=issue.getRemark();
        data[i][5]=issue;
        i++;
    }

if u know answer please share here..

Prasanth A R
  • 4,046
  • 9
  • 48
  • 76

3 Answers3

2

Instead of an array, use a dynamically resizable data structure in your implementation of AbstractTableModel. This EnvDataModel is an example that contains a Map<String, String>.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
2

In your previous question, You were using a DefaultTableModel. Keep in mind, a TableModel is a data structure in itself. There is no need at to store the data in two data structures, i.e. your data[][] and the DefaultTableModel. The underlying structure of DefaultTableModel is a dynamic Vector of Vectors.

What you can do is this. Just declare your DefaultTableModel with 0 rows, using this constructor

Then just add rows dynamically to the structure with

  • public void addRow(Object[] rowData) - Adds a row to the end of the model. The new row will contain null values unless rowData is specified. Notification of the row being added will be generated.

So basically, your declaration will be like this

String[] colName = {"Member", "Book", "Issue Date", "Return Date ", "Remarks" };
DefaultTableModel model = new DefaultTableModel(colName, 0);
JTable table = new JTable(model);

Then just add rows like

String member = "Stack";
String book = "overflow";
Data issueDate = date;
....
Object[] row = { member, book, issueDate, returnDate, remarks };
DefaultTableModel model = (DefaultTableModel)table.getModel();
model.addRow(row);

Please read the DefaultTableModel api documentation to see more constructors and methods available

Community
  • 1
  • 1
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
1

Instead of copying all the data from your List to the DefaultTableModel you can use your List as the data structure for a custom TableModel. Then you can add/remove Issue object from this TableModel.

See the JButtonTableModel.java example from Row Table Model for an simple example of how the RowTableModel can be extended to give you this functionality.

Using this approach the data is only ever in one place and you can access Issue objects directly from the TableModel.

camickr
  • 321,443
  • 19
  • 166
  • 288