Tuesday 10 February 2009

JTable

Here is simple example of how to add data to a JTable and get table to display. Note that I had already added the JScrollPane (JScrollPane2) to the window in the designer:

String[] columnNames = {"First Name",
"Last Name",
"Sport",
"# of Years",
"Vegetarian"};
Object[][] data = {
{"Mary", "Campione",
"Snowboarding", new Integer(5), new Boolean(false)},
{"Alison", "Huml",
"Rowing", new Integer(3), new Boolean(true)},
{"Kathy", "Walrath",
"Knitting", new Integer(2), new Boolean(false)},
{"Sharon", "Zakhour",
"Speed reading", new Integer(20), new Boolean(true)},
{"Philip", "Milne",
"Pool", new Integer(10), new Boolean(false)}
};
this.table = new JTable(data, columnNames);
this.table.setFillsViewportHeight(true);

jScrollPane2.add(this.table);
jScrollPane2.setViewportView(this.table);

FW: Java examples

Great web site about all things Java:

MessageDialog

Might be simple, but I am bound to forget - how to create a message box in java:

import javax.swing.JOptionPane;
JOptionPane.showMessageDialog(null, "My Message.");

Sunday 8 February 2009

This blog is going to track the creation of a simulation application from scratch to complete open source product.  At this stage I am getting my head around Java after years working with C#.