简体   繁体   English

跳到下一行时无法突出显示Jtable中的下一个可编辑单元格

[英]Unable to highlight the next editable cell in Jtable on tabbing to next Row

Below is my custom logic to tab to the next editable cell. 下面是我的自定义逻辑,以跳至下一个可编辑单元格。 Adds row automatically when tabbed from a particular column. 从特定列中制表符时自动添加行。

What works fine: 什么工作正常:

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. 添加新行时,焦点将自动移至下一列的第一行,因此当我开始键入时,它将从下一行的第一列进行键入。

What i need : 我需要的 :

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. 目前,尽管它正确地键入了该单元格,但我们显然不知道它指向该单元格。

Note : 注意 :

I have done this table.cellSelectionEnabled(true); 我已经完成了这张表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);

The getValueAt was returning null for a particular case and i changed null to an empty String "". 对于特定情况,getValueAt返回null,我将null更改为空字符串“”。 This resolved the issue. 这解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM