roguehippo Posted May 15, 2016 Share Posted May 15, 2016 (edited) Hey there, so im making a fighting script and im trying to make a method for creating a list of items to pick up that the user can put in. the problem im running into right now is that i beleive im doing everything right but on the button press it doesnt add anything to the table. This is my current code. http://pastebin.com/rKUbk6Kz this is how the gui looks if a visual is needed. Edited May 15, 2016 by roguehippo Quote Link to comment Share on other sites More sharing options...
DragonAlpha Posted May 15, 2016 Share Posted May 15, 2016 http://stackoverflow.com/questions/3549206/how-to-add-row-in-jtable Quote Link to comment Share on other sites More sharing options...
LoudPacks Posted May 16, 2016 Share Posted May 16, 2016 (edited) Hey there, so im making a fighting script and im trying to make a method for creating a list of items to pick up that the user can put in. the problem im running into right now is that i beleive im doing everything right but on the button press it doesnt add anything to the table. This is my current code. http://pastebin.com/rKUbk6Kz this is how the gui looks if a visual is needed. 33b382a23cc37a452e6c56018eb52823.png String[] columnNames = { "Username", "Rank" }; JTable table = new JTable(new DefaultTableModel(data.getData(), columnNames){ @Override public boolean isCellEditable(int row, int column) { //Disable editing of all cells return false; } }); public Object[][] getData() { Object[][] data = new Object[num of entries][num column]; int i = 0; for(String s : inputMap.keySet()){ data[i][0] = "entry i, column 0"; data[i][1] = "entry i, column 1"; i++; } else{ continue; } } return data; } some leaked code. I had a Data class that would write and read to a file and it puts the data into a Object[][] and then the table can load it. The first dimension in the array is the entry count, the second dimension is the column amount. For example if I had 2 entries and each entry had a name, birthdate, and hometown it would be Object[2][3] and then it would populate 3 columns with 2 entries. Edited May 16, 2016 by LoudPacks 1 Quote Link to comment Share on other sites More sharing options...
liverare Posted May 19, 2016 Share Posted May 19, 2016 The problem with JTables is that they're tabular (surprise). While other Swing components are using generic types to make life easier, JTables remain annoying to implement. But don't worry, I am working on a solution! Quote Link to comment Share on other sites More sharing options...