我有追随者类,我想得到JTable
它。
public class TimeTable extends JPanel
{
private JTable table;
public TimeTable (int semestre)
{
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
table = new JTable(new MyTableModel());
table.setFillsViewportHeight(true);
table.setPreferredScrollableViewportSize(new Dimension(510, 350)); //imposta le dimensioni della tabella
JScrollPane jps = new JScrollPane(table);
add(jps);
add(new JScrollPane(table));
table.setCellSelectionEnabled(true);
table.setRowHeight(40);
TableColumn tcol;
for (int i=0; i<table.getColumnCount(); i++)
{
tcol = table.getColumnModel().getColumn(i);
tcol.setCellRenderer(new CustomTableCellRenderer());
}
}
public class MyTableModel extends AbstractTableModel {//instructions that customize my table}
public class CustomTableCellRenderer extends DefaultTableCellRenderer{//other instructions that customize my table }
}
请注意,我不想在 Frame 中看到表格。我还没有这样做:现在我需要MouseListener
在表中添加一个,而我拥有的类是一个JPanel
扩展。我怎样才能做到这一点?