选择错误行通过触摸设备返回。

当设备是
pointerPressed
方法中的触摸屏时,我想使用表的选定行,并且得到的值是错误的:例如,我单击了第三行(PS:标题行为-1),我在
System.out.println
中得到0作为值!当我单击另一行时,我得到之前选择的行! 那么如何将LWUIT与所选行同步?     
已邀请:
        好的,我找到了解决方案:在构造函数中我写道:
for (short idxComp=3; idxComp<tList.getComponentCount(); idxComp++)
        {
            tList.getComponentAt(idxComp).addFocusListener(this);
        }
isTableSelected = false;
这是实现的方法:
public void pointerPressed(int x, int y)
    {
        int startX, startY, endX, endY, nbComps;
        nbComps = tList.getComponentCount();
        startX = tList.getComponentAt(3).getAbsoluteX();
        endX = tList.getComponentAt(5).getAbsoluteX() + tList.getComponentAt(5).getWidth();
        startY = tList.getComponentAt(3).getAbsoluteY();
        endY = tList.getComponentAt(nbComps-1).getAbsoluteY() + tList.getComponentAt(nbComps-1).getHeight();
        if ( (x >= startX && x <= endX) && (y >= startY && y <= endY) )
        {
            isTableSelected = true;
            if ( (x >= selectedComp.getAbsoluteX() && x <= (selectedComp.getAbsoluteX()+selectedComp.getWidth())) && (y >= selectedComp.getAbsoluteY() && y <= (selectedComp.getAbsoluteY()+selectedComp.getHeight())) )
                afficheFicheCredit(selectedRow);
        }
    }
    public void focusGained(Component comp) {
        tList.repaint();
        selectedComp = tList.getComponentAt(3*selectedRow+3);
        if (isTableSelected)
        {
            isTableSelected = false;
            selectedRow = tList.getSelectedRow();
            afficheFicheCredit(selectedRow);
        }
    }
    

要回复问题请先登录注册