Advertisement
Advertisement
| 06.18.2008 at 03:11PM PDT, ID: 23497112 |
|
[x]
Attachment Details
|
||
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: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: |
import java.util.Vector;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;
public class ComboBoxTable extends JTable {
public ComboBoxTable(TableModel tm) {
super(tm);
tableModel = (ComboBoxOutputTableModel)tm;
}
ComboBoxOutputTableModel tableModel;
Vector valuesVector = null;
public TableCellRenderer getCellRenderer(int row, int column){
if(column == 1){
setValuesVector(row,column);
MyComboBoxRenderer renderer = new MyComboBoxRenderer(valuesVector);
getColumnModel().getColumn(1).setCellRenderer(renderer);
return renderer;
}
else return super.getCellRenderer(row, column);
}
public TableCellEditor getCellEditor(int row, int column)
{
if (column == 1){
MyComboBoxEditor editor = new InegQueueComboBoxEditor(valuesVector);
return editor;
}
else return super.getCellEditor(row, column);
}
/**
* Gets the collection from the table model data for the current row and populates
* the Vector that will be set to a comboBox with it
* tableModel.getData() returns Object[int][String[]]
*/
public void setValuesVector(int row, int column){
Object[] modelRow = tableModel.getData()[row];
this.valuesVector = new Vector((Vector)modelRow[column]);
}
}
public class MyComboBoxRenderer implements TableCellRenderer {
public MyComboBoxRenderer(Vector v){
}
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
JComboBox comboBox = null;
if(value == null){
comboBox = new JComboBox();
}else{
Vector vector = (value instanceof Vector)?(Vector)value:new Vector();
comboBox = new EiiComboBox(vector);
comboBox.setFont(LookAndFeelConstants.getLabelFont());
}
if (isSelected) {
comboBox.setForeground(table.getSelectionForeground());
comboBox.setBackground(table.getSelectionBackground());
} else {
comboBox.setForeground(table.getForeground());
comboBox.setBackground(table.getBackground());
}
return comboBox;
}
}
public class MyComboBoxEditor extends AbstractCellEditor implements TableCellEditor {
private Component comp = null;
private int r = 0;
private int c = 0;
public MyComboBoxEditor(Vector items) {
super();
}
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
Component com = null;
r = row;
c = column;
JComboBox comboBox;
if(value == null || value.toString().length() == 0) com = new JTextField("");
else if(value instanceof Vector){
comboBox = new JComboBox();
if(comboBox.getModel().getSize() > 0){
// clear it...
comboBox.removeAllItems();
}
comboBox.setModel(new DefaultComboBoxModel((Vector)value));
comboBox.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e) {
//nothing implemented here yet
}
});
com = comboBox;
}else {
comboBox = new JComboBox();
if(comboBox.getModel().getSize() > 0){
// clear it...
comboBox.removeAllItems();
}
comboBox.addItem(value);
com = comboBox;
}
comp = com;
return com;
}
//inherited
public Object getCellEditorValue() {
return null;
}
}
|