|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Member
Iscritto dal: Jun 2001
Messaggi: 27
|
[JAVA] JComboBox in JTable
Salve a tutti,
sto lavorando ad un progetto la cui interfaccia grafica è la seguente: http://img44.imageshack.us/img44/6571/immaginexcq.jpg Per testare il funzionamento dei componenti ho creato una classe che mi carica direttamente in memoria gli oggetti e quando vado a riempire la JComboBox,resta vuota...credo che l'errore sia nell'implementazione della classe: ed in particolare degli ultimi 2 metodi... Codice:
public class ModelloTabellaOrario extends DefaultTableModel {
private String[] columnNames = {"Aula",
"Ins.", "Coorte", "Info",};
private Object[][] data = new String[][]{{"","","",""}};
@Override
public int getColumnCount() {
return 4;
}
@Override
public int getRowCount() {
return 1;
}
@Override
public String getColumnName(int col) {
return columnNames[col];
}
@Override
public boolean isCellEditable(int row, int col) {
if (col < 2) {
return true;
} else {
return false;
}
}
@Override
public Object getValueAt(int row, int col){
return data[row][col];
}
@Override
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
}
PS Posto anche il codice del renderer e dell'editor della JComboBox Codice:
class MyComboBoxEditor extends DefaultCellEditor {
public MyComboBoxEditor(JComboBox combo) {
super(combo);
}
}
Codice:
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
if (!isSelected) {
setBackground(Color.white);
} else if (isSelected) {
setForeground(table.getSelectionForeground());
super.setBackground(table.getSelectionBackground());
} else {
setForeground(table.getForeground());
setBackground(table.getBackground());
}
setSelectedItem(value);
return this;
}
}
__________________
Nottarget |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 07:40.



















