I'm trying to list some data gathered from files into a JTable - here's the code I'm using:
/* Packages listed in a JTable */
Object[] columnNames = {"Package", "Version", "Installed"};
int packageCount = getPackageCount();
Object[][] data = new Object[packageCount][2];
Scanner dbIndex = new Scanner(new File("/opt/npkg/dbindex.npkg"));
int row = 0;
while(dbIndex.hasNext()) {
PackageReader pkg = new PackageReader(new File("/opt/npkg/" + dbIndex.nextLine() + ".pkg"));
data[row][0] = pkg.getPackageName();
data[row][1] = pkg.getPackageVersion();
row++;
}
JTable table = new JTable(data, columnNames);
table.setAutoResizeMode(4);
table.setSize(windowSize.width, 20);
table.setGridColor(Color.LIGHT_GRAY);
table.revalidate();
cpanel.add(table);
Here are some of the problems I'm running into:
- The only data I can see is in the first row. Anything after that, I have to click on
every element in the corresponding row to see any more data.
- The table stays very very small in the centre of the cpanel (JPanel - "Centre Panel")
Any help?