I'm new to java and I want to take data that I have stored in a Map and add it to a table. As I was reading the java tutorials on "How to Use Tables" I found myself lost looking at the sample code below:
String[] columnNames = { "blah", "blah" };
Object[][] data = {
{"Kathy", "Smith",
"Snowboarding", new Integer(5), new Boolean(false)},
{"John", "Doe",
"Rowing", new Integer(3), new Boolean(true)},
{"Sue", "Black",
"Knitting", new Integer(2), new Boolean(false)},
{"Jane", "White",
"Speed reading", new Integer(20), new Boolean(true)},
{"Joe", "Brown",
"Pool", new Integer(10), new Boolean(false)}
};
I'm supposed to then instantiate a JTable object like this:
JTable table = new JTable(data, columnNames);
I'm confused as to how I would populate data from a map into an array of objects like they did in the example above? The data in the rows from my map will be a String and a Float.
Ideally, I would have two columns (just an example), { "File", "Size" } and then my rows would put the string for the file name and the float for size.
I tried various things which I feel are too silly to put here, but nothing worked.
MapTableModelfor that. It would accept aMapin the constructor. Column header names would beKeyandValue. ..