我有这个JTable:
jTable1 = new javax.swing.JTable();
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null, null, null},
{null, null, null, null, null, null},
{null, null, null, null, null, null},
{null, null, null, null, null, null},
{null, null, null, null, null, null},
{null, null, null, null, null, null},
{null, null, null, null, null, null},
{null, null, null, null, null, null},
{null, null, null, null, null, null},
{null, null, null, null, null, null},
{null, null, null, null, null, null},
{null, null, null, null, null, null},
{null, null, null, null, null, null},
{null, null, null, null, null, null},
{null, null, null, null, null, null},
{null, null, null, null, null, null},
{null, null, null, null, null, null},
{null, null, null, null, null, null},
{null, null, null, null, null, null},
{null, null, null, null, null, null},
{null, null, null, null, null, null},
{null, null, null, null, null, null},
{null, null, null, null, null, null},
{null, null, null, null, null, null},
{null, null, null, null, null, null},
{null, null, null, null, null, null},
{null, null, null, null, null, null},
{null, null, null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4", "Title 5", "Title 6"
}
));
jTable1.setRowSelectionAllowed(true);
jTable1.setColumnSelectionAllowed(false);
jTable1.setRowSelectionAllowed(true);
jTable1.setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
jTable1.setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
jTable1.getTableHeader().addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
int col = jTable1.columnAtPoint(e.getPoint());
jTable1.setColumnSelectionInterval(col, col);
}
});
/*All of this just makes it so that the table will automatically add new
rows as the user scrolls down*/
jScrollPane1.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener(){
@Override
public void adjustmentValueChanged(AdjustmentEvent e) {
int extent = jScrollPane1.getVerticalScrollBar().getValue()
+ jScrollPane1.getVerticalScrollBar().getModel().getExtent();
int max = jScrollPane1.getVerticalScrollBar().getMaximum();
int prox = max - extent;
System.out.println(prox);
if(prox <= 144){
DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
model.addRow(new Object[]{null, null, null, null, null, null});
}
}
});
jScrollPane1.setViewportView(jTable1);
我希望用户能够选择整个行,因此我启用了行选择。这样,如果他们单击一个单元格,则整行都将突出显示。
我也希望用户能够选择整个列,因此我将列标题设置为(我认为我做对了)单击时选择整个列。但是,这将不起作用,因为已启用行选择。但是我仍需要启用行选择,因为除了能够选择整个列之外,我还需要用户能够选择整个行。
开始似乎无法选择整个行,同时也可以选择整个列。
我正在努力完成这个项目,时间紧迫,这个问题使一切都陷入了停顿。
我该如何解决这个问题?