import java.awt.*; import javax.swing.*; import javax.swing.table.*; import javax.swing.event.*; /** Esta clase implementará un panel que mostrara una tabla con los semestres y sus ramos. */ public class Tabla extends JPanel { private static JTable table; public Tabla(){ } /** Constructor de la clase */ public Tabla(final Object[][] rowData, final String[] columnNames, final boolean b) { super(new GridLayout(1,0)); TableModel dataModel = new AbstractTableModel() { public int getColumnCount() { return columnNames.length; } public int getRowCount() { return rowData.length;} public Object getValueAt(int row, int col) {return rowData[row][col];} public String getColumnName(int column) {return (String)columnNames[column];} public Class getColumnClass(int c) {return getValueAt(0, c).getClass();} public boolean isCellEditable(int row, int col) {return false;} public void setValueAt(Object aValue, int row, int column) { rowData[row][column] = aValue; } }; DefaultListSelectionModel rm = new DefaultListSelectionModel(); DefaultTableCellRenderer colorRenderer = new DefaultTableCellRenderer() { public void setValue(Object value) { if (value instanceof Celda) { Celda c = (Celda) value; if (b){ setBackground(c.getColorFondo()); setForeground(c.getColorText()); } else{ setBackground(Color.white); setForeground(Color.black); } setText(c.toString()); } else { super.setValue(value); } } }; table = new JTable(dataModel); table.setRowSelectionAllowed(false); table.setColumnSelectionAllowed(false); table.setCellSelectionEnabled(b); table.setSelectionModel(rm); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setDragEnabled(false); table.setPreferredScrollableViewportSize(new Dimension(600, 120)); for (int i=0; i