java - Repeated values when inserting rows into JTable -


I have a problem putting rows in JTable and I do not know what the problem is.

I do exactly this:

  (DefaultTableModel) myJTable.getModel ()). InsertRow (0, webSiteDownloader.getWebSites (). ToArray ());  

Website Downloader is an object that contains ArrayList . I can call that array method getWebSites .

The problem is that when I insert a line, the second one adds, then JTable only shows the first one but repeated twice, was I quite clear?

thks: D

I'll take a shot and think in the dark You want to accomplish something like this:

  DefaultTableModel dtm = (DefaultTableModel) myJTable.getModel (); (For MyRowObject line: webSiteDownloader.getWebSites ()) {dtm.insertRow (0, row.toArray ()); }  

Is there any special reason that you are using raw instead of addRow?

In addition to this, I would really like to suggest that you expand your special purpose titled table model by Basic Uncharted Example:

  Public category MyTableModel AbstractTableModel {protected list & Lt; MyObject & gt; Rows; Public MyTableModel () {Lines = New Arreelist & lt; MyObject & gt; (); } Add Public Zero (MyObject obj) {rows.add (obj); } @ Override Public Intervount () {Return Raps.im; } @ Override Public Ent column column () {// This value will be continuous, but generally you want to // // want to override getColumnName to return column names from an array, and in that case You can return length // Return of the array with the names of columns instead 2; } @ Override public object getValueAt (int row, int column) {MyObject obj = rows.get (line); // Change it to match your column switch (column) {case 0: return obj.getId (); Case 1: Return obj.getName (); } Return tap; }}  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -