Java GUI cheatsheet

swing mostly

JTable

public class CustomTableModel extends AbstractTableModel {
    public int getRowCount();
    public int getColumnCount();
    public Object getValueAt(int row, int column);
    //////
    public String getColumnName(int column);
}
 
// example of usage
CustomTableModel tmodel = new CustomTableModel();
JTable table = new JTable(tmodel);
public class CustomTableCellRenderer extends DefaultTableCellRenderer {
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                                                   boolean hasFocus, int row, int column) {
        Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
 
        // do your formating...
 
        return cell;
    }
 
// example of usage:
table.setDefaultRenderer(Object.class, new CustomTableCellRenderer());
 
coding/java/gui_sheet.txt · Last modified: 2008/05/12 09:32 (external edit)
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki