I have less experience with Java Swing and I want to create a dynamic list where for each element must be specified 2 parameters.
I have n elements, where the number n i
How about using a JTable with two columns, one for each data value?
There's a good tutorial on using tables at: http://docs.oracle.com/javase/tutorial/uiswing/components/table.html
By Using ArrayList You can :
import java.util.ArrayList;
public class ArrayList2d<Type>
{
ArrayList<ArrayList<Type>> array;
public ArrayList2d()
{
array = new ArrayList<ArrayList<Type>>();
}
public void ensureCapacity(int num)
{
array.ensureCapacity(num);
}
public void ensureCapacity(int row, int num)
{
ensureCapacity(row);
while (row < getNumRows())
{
array.add(new ArrayList<Type>());
}
array.get(row).ensureCapacity(num);
}
public void Add(Type data, int row)
{
ensureCapacity(row);
while(row >= getNumRows())
{
array.add(new ArrayList<Type>());
}
array.get(row).add(data);
}
public Type get(int row, int col)
{
return array.get(row).get(col);
}
public void set(int row, int col, Type data)
{
array.get(row).set(col,data);
}
public void remove(int row, int col)
{
array.get(row).remove(col);
}
public boolean contains(Type data)
{
for (int i = 0; i < array.size(); i++)
{
if (array.get(i).contains(data))
{
return true;
}
}
return false;
}
public int getNumRows()
{
return array.size();
}
public int getNumCols(int row)
{
return array.get(row).size();
}
}