1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| // Columns titles
final String[] names = {
"Schema",
"Instructions"
};
ImageIcon object_AA = new ImageIcon(getClass().getResource("/Images/Sac.jpg"));
ImageIcon object_AB = new ImageIcon(getClass().getResource("/Images/Bob.jpg"));
// Create the dummy data (a few rows of names)
final Object[][] data00 = {
{object_AA,"blabla blabla\nbla\nbla\nbla..."},
{object_AB,"Blabla blabla\nBla\nBla\nBla..."}
};
// Create a model of the data.
dataModel00 = new AbstractTableModel() {
public int getColumnCount() { return names.length; }
public int getRowCount() { return data00.length;}
public Object getValueAt(int row, int col) {return data00[row][col];}
public String getColumnName(int column) {return names[column];}
public Class getColumnClass(int c) {return getValueAt(0, c).getClass();}
public boolean isCellEditable(int row, int col) {return true;}
public void setValueAt(Object aValue, int row, int column) { data00[row][column] = aValue; }
};
// Create a JTable with custom Renderer.
this.elementsTable=new JTable(dataModel00){
public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
Component c=null;
JTextArea textArea=null;
JButton schemaButton=null;
Object value = getValueAt(row, column);
int offset = 0;
if (value instanceof String){
textArea=new JTextArea((String) value);
c=textArea;
}else if (value instanceof ImageIcon){
schemaButton=new JButton((ImageIcon) value);
c=schemaButton;
}else{
System.out.println("ISInstructionPanel: Unexepected Object!");
}
// Set background colors
if(c!=null){
if(getSelectedRow()==row){
c.setBackground(getSelectionColor(0));
Font cFont = new Font(c.getFont().getFontName(),Font.BOLD,c.getFont().getSize());
c.setFont(cFont);
}
else if ((row%2)==0) {
c.setBackground(getForegroundColor(75));
} else {
c.setBackground(getForegroundColor(150));
}
}
return c;
}
};
this.elementsTable.setRowHeight(100);
this.elementsTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
packColumns(this.elementsTable,2);
this.elementsScrollTable = new JScrollPane(this.elementsTable);
this.elementsTable.setCellSelectionEnabled(true);
Action DummyAction = new AbstractAction("DummyAction") {
public void actionPerformed(ActionEvent e) {
System.out.println("DummyAction");
}
};
this.elementsTable.getActionMap().put("DummyAction", DummyAction);
this.elementsTable.getInputMap().put(
javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ENTER,0),
"DummyAction"); |
Partager