Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>use <code>clone()</code> method thats create <strong>exact copy of object</strong> what you want to clone. To allow cloning your class must implement interface <code>Cloneable</code>. Then you must <strong>override</strong> clone method from interface which you implements.</p> <p><strong>Little example:</strong></p> <pre><code>public class TableClass implements Cloneable { private DefaultTableModel model; @Override public Object clone() { DefaultTableModel cloned = null; try { cloned = (DefaultTableModel) super.clone(); } catch (CloneNotSupportedException ex) { Logger.getLogger(TableClass.class.getName()).log(Level.SEVERE, null, ex); } return cloned; } </code></pre> <p>Because of <code>clone()</code> method returns instance of <code>Object</code>, you must cast to type of your object: <code>cloned = (DefaultTableModel) super.clone()</code></p> <p>So this is how to work <code>clone()</code>. Now you can implement your own tableMode.</p> <p><strong>Basic example:</strong></p> <pre><code>public class YourTableModel extends AbstractTableModel implements Cloneable { private static final String[] columnNames = {"URL", "Progress", "Size", "Status"}; private static final Class[] columnClasses = {String.class, String.class, String.class, String.class}; private List&lt;T&gt; yourData; @Override public Object clone() { YourTableModel cloned = null; try { cloned = (YourTableModel) super.clone(); } catch (CloneNotSupportedException ex) { Logger.getLogger(TableClass.class.getName()).log(Level.SEVERE, null, ex); } return cloned; } @Override public Object getValueAt(int row, int col) { switch (col) { case 0: return yourData.getName(); case 1: return yourData.getAge(); case 2: return yourData.getAddress(); case 3: return yourData.getSomethingElse(); } return ""; } @Override public int getColumnCount() { return columnNames.length; } @Override public int getRowCount() { return downloadList.size(); } @Override public String getColumnName(int col) { return columnNames[col]; } public Class getClassName(int col) { return columnClasses[col]; } } </code></pre> <p>This way your implement your own model also clone() method and then you can cloning this objects. But there is also other approaches like wrote <strong>@vizier</strong></p> <p>Hope it helps!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload