跳到下一行时无法突出显示Jtable中的下一个可编辑单元格 [英] Unable to highlight the next editable cell in Jtable on tabbing to next Row

查看:96
本文介绍了跳到下一行时无法突出显示Jtable中的下一个可编辑单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的自定义逻辑,可跳至下一个可编辑单元格.从特定列中选择标签时,会自动添加行.

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中的下一个可编辑单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆