I want to create a simple table using the JTable wherein the values will come from the multi-array object. But when i try to pass that data object and the array of strings for the column names to the constructor, i get ArrayIndexOutOfBoundsException. The .setValueAt method works on this but i want to populate the table by using array.
here is the constructor part of the class.
public Table(){
super("My Table");
String[] colName = {"Name","Age","Address"};
System.out.println("ok");
Object tableValue[][] = {
{"Dianne Delos Reyes","17", "Lambakin"},
{"Maya Fojas", "30", "Dubai"},
{"Robert Alcantara", "Lambakin"}
};
table = new JTable(tableValue,colName);
table.setPreferredScrollableViewportSize(new Dimension(500, 50));
table.setFillsViewportHeight(true);
add(table);
scrollPane = new JScrollPane(table);
add(scrollPane);
}
Any idea why i get such error? thanks in advance
It contains only
two valueselse where you have used3values. If it tries to access thethird valueit will getArrayIndexOutOfBoundsException