问题描述
下面是我的自定义逻辑,可跳至下一个可编辑单元格.从特定列中选择标签时,会自动添加行.
Below is my custom logic to tab to the next editable cell. Adds row automatically when tabbed from a particular column.
有效的方法:
添加新行时,焦点会自动移至下一列的第一行,以便在我开始键入时会从下一行的第一列进行键入.
When new row is added focus is automatically on the first row of next column so that when i start typing it types from first column of next row.
我需要什么:
突出显示焦点所在的单元格,以便用户知道焦点位于下一行的第一列.目前,尽管它正确地键入了该单元格,但我们显然不知道它指向该单元格.
Highlight the cell in focus so that the user knows that the focus is on first column of next row. At the moment although it types correctly into the cell we dont know visibly that it is pointing to that cell.
注意:
我已经完成了这个table.cellSelectionEnabled(true);
,但仍然无法正常工作.
I have done this table.cellSelectionEnabled(true);
and still doesnt work.
InputMap im = itemTable.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
final Action oldTabAction = itemTable.getActionMap().get(im.get(tab));
Action tabAction = new AbstractAction()
{
public void actionPerformed(ActionEvent e)
{
oldTabAction.actionPerformed( e );
JTable table = (JTable)e.getSource();
int rowCount = table.getRowCount();
int columnCount = table.getColumnCount();
int row = table.getSelectedRow();
int column = table.getSelectedColumn();
FLItemRuleInfo itemRuleInfo = itemTableModel.getItemRuleInfoList().get(row);
while (! itemTableModel.isCellEditable(row, column) )
{
if((itemRuleInfo.getItem()==null || itemRuleInfo.getItem().getItemId()==null || itemRuleInfo.getItem().getItemId().isEmpty())){
column=1;
break;
}
column += 1;
if (column == columnCount)
{
column = 1;
row +=1;
}
/* if (row == rowCount)
{
row = 0;
}*/
if (row == table.getSelectedRow()
&& column == table.getSelectedColumn())
{
break;
}
}
table.changeSelection(row, column, false, false);
if(column==8 && (row == rowCount-1) && itemRuleInfo.getItem()!=null){
itemTableModel.addRow(new FLItemRuleInfo());
}
}
};
itemTable.getActionMap().put(im.get(tab), tabAction);
推荐答案
对于特定的情况,getValueAt返回null,并且我将null更改为空字符串".这样就解决了问题.
The getValueAt was returning null for a particular case and i changed null to an empty String "". This resolved the issue.
这篇关于跳到下一行时无法突出显示Jtable中的下一个可编辑单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!