ciao a tutti, sto lavorando ad un progetto con valy12. grazie degli aiuti ma nn siamo ancora riuscite a risolvere il problema.
se inseriamo la chiamata del metodo cellrender senza generare dinamicamente la tabella funziona e l'abbiamo fatto così...
codice:
private JTable getJTable() {
DefaultTableModel dt=new DefaultTableModel(10,5);
Object[] NomeColumn = new Object[5];
for (int i=0;i<5;i++)
NomeColumn[i]= (String)"attributo ";
dt.setColumnIdentifiers(NomeColumn);
for(int i=0;i<10;i++)
for(int j=0;j<5;j++)
dt.setValueAt(" ciao babba!!! ",i,j);
jTable=new JTable(dt);
Vector<Integer> righeRosse = new Vector<Integer>();
righeRosse.add(0);
MioCellRenderer mcr = new MioCellRenderer(righeRosse);
for(int i=0;i<5;i++)
jTable.getColumnModel().getColumn(i).setCellRenderer(mcr);
//jTable.getColumnModel().getColumn(2).setCellRenderer(mcr);
jTable.setVisible(true);
jTable.setAutoscrolls(true);
jTable.setCellSelectionEnabled(false);
jTable.setEnabled(false);
jTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
return jTable;
}
solo che se riportiamo lo stesso ragionamento quando creiamo le tabelle dinamiche non funziona!!!!!!!
codice:
private void initialize() throws SQLException, IOException {
this.setVisible(true);
this.setBounds(0,30,1005,572);
this.setEnabled(true);
//****CREAZIONE PANNELLI****//
for(int i=0;i<dim;i++){
this.addTab(dataBaseConnection.getDBSchema().getTable(i).getNameTable().toUpperCase(), null,new JTabbedPane() , null);
}
}
//****CREAZIONE PANNELLI INTERNI AL PANNELLO PRINCIPALE****//
private JTabbedPane getTbdPane(int i, JTabbedPane TbdPane) throws SQLException {
TbdPane.removeAll();
TbdPane.setName(dataBaseConnection.getDBSchema().getTable(i).getNameTable().toUpperCase());
TbdPane.setTabPlacement(JTabbedPane.LEFT);
table = new JTable(dtm);
SplitMod = new JSplitPane();
Vector<Integer> righeRosse = new Vector<Integer>();
righeRosse.add(0);
MioCellRenderer mcr = new MioCellRenderer(righeRosse);
table.getColumnModel().getColumn(0).setCellRenderer(mcr);
TbdPane.addTab("MODIFICA", null, getSplitMod(dataBaseConnection.getDBSchema().getTable(i)));
return TbdPane;
}
codice:
public class MioCellRenderer extends DefaultTableCellRenderer{
/**
*
*/
private Vector<Integer> righeRosse = new Vector<Integer>();
private static final long serialVersionUID = 1L;
public MioCellRenderer(Vector<Integer> v){
this.righeRosse = v;
}
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);
if(righeRosse.contains(row)) //per esempio
cell.setBackground( Color.red );
else
cell.setBackground( Color.white );
return cell;
}
/*private static final long serialVersionUID = 1L;
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);
if(row==0)
cell.setBackground( Color.red );
else
cell.setBackground( Color.white );
return cell;
}*/
}
e da l'errore...
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0 >= 0 sulla riga table.getColumnModel().getColumn(0).setCellRendere r(mcr);
ed inoltre riporta L'ERRORE sull'evento...
codice:
public void stateChanged(ChangeEvent arg0){
if (arg0.getSource().getClass().toString().equals(Tool.class.toString()))
{
JTabbedPane TbdPane = (JTabbedPane) arg0.getSource(); //nn ho capito questo passaggio!
typeRich = TbdPane.getSelectedIndex();
System.out.println("numerooo"+typeRich);
System.out.println("Questo è quello che torna:"+ TbdPane.getSelectedComponent().getClass().toString());
if(typeRich<dataBaseConnection.getDBSchema().getSize()){
try {
getTbdPane(typeRich, (JTabbedPane) TbdPane.getSelectedComponent());
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}