U .NET-a sam obicno za prikaz podataka koristio DataGridView i zanjega prikacio neku List-u koja sadrzi podatke, isto pokusavam u javi i to radi ali na malo drugaciji nacin pa me zanima:
1) Da li uvek kada hocu iz neke liste da ubacim podatke u JTable ta lista mora da bude 'Vector' (Kako sam radio dole u kodu), posto sam probao da napravim List, ArrayList... i nece tako da zakaci podatke?
2) U .NET-u ovo radim tako sto kazem
Code:
myDataGrid.DataSource = myListWithData;
da li u Java-i ima neki property koji moze da odradi istu operaciju, ili uvek mora kao sto sam dole uradio?myDataGrid.DataSource = myListWithData;
3) Dodao sam 'Vector' tip i svuda gde ga koristim imam warning:
Citat:
Vector is a raw type. References to generic type Vector<E> should be parameterized
Code:
Vector row;
Vector rows = new Vector();
Vector columnNames = new Vector();
columnNames.addElement("BookTitle");
columnNames.addElement("PublisherDirectoryName");
columnNames.addElement("FullBookLocation");
columnNames.addElement("BookExtension");
for (BookVO b : booksList)
{
row = new Vector();
row.addElement(b.BookTitle);
row.addElement(b.PublisherDirectoryName);
row.addElement(b.FullBookLocation);
row.addElement(b.BookExtension);
rows.add(row);
}
JTable table = new JTable(rows, columnNames);
JScrollPane scrollPane = new JScrollPane(table);
frame.add(scrollPane);
Vector row;
Vector rows = new Vector();
Vector columnNames = new Vector();
columnNames.addElement("BookTitle");
columnNames.addElement("PublisherDirectoryName");
columnNames.addElement("FullBookLocation");
columnNames.addElement("BookExtension");
for (BookVO b : booksList)
{
row = new Vector();
row.addElement(b.BookTitle);
row.addElement(b.PublisherDirectoryName);
row.addElement(b.FullBookLocation);
row.addElement(b.BookExtension);
rows.add(row);
}
JTable table = new JTable(rows, columnNames);
JScrollPane scrollPane = new JScrollPane(table);
frame.add(scrollPane);