java - ArrayList output to JTable -


Yes, I'm gone, yes I've read, yes, I'm still trapped

I have an ArrayList of objects in class, I am returning an ArrayList of objects in class A, by calling a method from A. B. (in the same return type :) in CLassB, I do all the processing and storing objects. Features in an array of class types of objects

class B:

  classb object = new class (B); ArrayList & LT; ClassB & gt; ArrayOfObjects = New ArrayLight & lt; & Gt; (); Int count = 0; While (calculation and lieutenant; 10) /// Many things are going on here but the general concept is this; Object.attribute1 = "object.attribute2 =" read something in the object, read something in the "object.attribute2 =" object. Object 3 = "Read something in the object". Object object = 4 "Array objects in some data read." ); Count ++; }  

Category:

  Array list & lt; Class B & gt; ArrayOfObjects = ClassBObject.method (); String [] column = {"column 1", "column2", "column3", "column4", "column5"}; Default Table Model Table Models = New DefaultTel Model (column, 0); JTable table = new JTable (tablemodel); Int i = 0; While the variable string v1 = arrayOfObjects .get (i) .attribute1; for (i & lt; arrayOfObjects.size ()) {// v; String v2 = arrayOfObjects .get (i) .attribute2; String v3 = arrayOfObjects .get (i) .attribute3; String v4 = arrayOfObjects .get (i) .attribute4; String v5 = arrayOfObjects .get (i) .attribute5; Object [] row = {v1, v2, v3, v4, v5}; TableModel.addRow (line); I ++; } Jeffrey Frame = New JFram ("Table Title"); Zpean panel = new zpn (); Panel.setLayout (new border layout ()); JScrollPane tableContainer = new JScrollPane (table); Panel.add (TableContainer, Border Layout, CA); . Frame.getContentPane () add (panel); Frame.pack (); Frame.setVisible (true);  

Problem: With the above code, the table only displays the last object which is repeated several times in the form of a loop's execution. I want to remove the attributes from the object array from each object, where the counter is used to match the element of the object's array.

I hope that enough information was given to provide me enough background, thanks to the root of the problem in advance!

OK, now we see your problem (potential)!

  Classb Object = New Classby (); ArrayList & LT; ClassB & gt; ArrayOfObjects = New ArrayLight & lt; & Gt; (); Int count = 0; While (calculation and lieutenant; 10) /// Many things are going on here but the general concept is this; Object.attribute1 = "object.attribute2 =" read something in the object, read something in the "object.attribute2 =" object. Object 3 = "Read something in the object". Object object = 4 "Array objects in some data read." ); Count ++; }  

Every time you create a new object in the loop!

Try instead:

  // ** * Do not create objects * once * while outside the loop! // class B object = new square b (); ArrayList & LT; ClassB & gt; ArrayOfObjects = New ArrayLight & lt; & Gt; (); Int count = 0; While (count & lt; 10) {// *** Create a new one for each walk of the loop instead! Class B Object = New Class B (); /// ************************************************************************************************** ************************************************************************************ Object Attribute2 = "read something in the object" object.attribute2 = "read something in the object. Object 3 = "Read something in the object". Object object = 4 "Array objects in some data read." ); Count ++; }  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -