GUI
FormLayout
FormLayout layout = new FormLayout(
// columns
"left:pref, 10dlu, " +
"right:pref, 5dlu, 80dlu, pref",
// rows
"p, 3dlu, " +
"p, 3dlu, " +
"p, 10dlu, " +
"p, 3dlu, " +
"p, 3dlu, " +
"p , 3dlu, p");
//Using this panel builder
builder = new PanelBuilder(layout);
builder.setDefaultDialogBorder();
CellConstraints cc = new CellConstraints();
//Add a JButton
builder.addSeparator(new JButton("A Button"), cc.xyw(1, 1, 6));
JTables
Abstract Table Models
class Model extends AbstractTableModel {
static final long serialVersionUID = 1;
public int getColumnCount() {return columnNames.length;}
public int getRowCount() {return data.size();}
public String getColumnName(int col){return columnNames[col];}
public Object getValueAt(int row, int col){return data.get(row)[col]; }
//Nothing is Editable
public boolean isCellEditable(int row, int col){ return false; }
public void setValueAt(String value, int row, int col){
Object[] tmp = data.get(row);
tmp[col] = value;
data.set(row, tmp);
fireTableCellUpdated(row, col);
}
public Class<?> getColumnClass(int c) {return getValueAt(0, c).getClass();}
}
Cell Editors
public class DataEditor implements CellEditorListener{
public void editingCanceled(ChangeEvent e){
System.out.println("Editing Canceled"); }
public void editingStopped(ChangeEvent e){
//Get the cell editor and retrieve the value
DefaultCellEditor cell = (DefaultCellEditor)e.getSource();
String value = (String)cell.getCellEditorValue();
//Get the position of the edited cell
int row = table.getSelectedRow();
int col = table.getSelectedColumn();
//Make sure that we have a valid location before setting value
if (col != -1 && row != -1){
model.setValueAt(value, row, col);
System.out.println("newnode : " + newnode);
if (newnode){
System.out.println("newnode ran");
ls.reload();
}
}
else {
System.out.println("unable to retrieve cell information");
}
}
}