触摸设备返回了错误的 selectedRow

发布于 2024-11-15 03:17:48 字数 168 浏览 2 评论 0原文

当设备是触摸设备时,我想在 pointerPressed 方法中处理表格的选定行,并且我得到的是错误的值:例如,我单击了第三行(PS:标题行是 -1 ),我在 System.out.println 中得到 0 作为值!当我单击另一行时,我会得到之前选择的行! 那么如何将LWUIT与所选行同步呢?

I want to work with the selected row of a Table when the device is a touch one in the pointerPressed method , and what I get is a wrong value : for example I clicked the third line ( PS : the header line is -1 ) and I got 0 as a value in the System.out.println ! And when I click another row then I get the row I selected before !
So how to synchronize LWUIT with the selected row ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丶情人眼里出诗心の 2024-11-22 03:17:48

好的,我找到了解决方案:在我编写的构造函数中:

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);
        }
    }

Ok , I found the solution : in the constructor I wrote :

for (short idxComp=3; idxComp<tList.getComponentCount(); idxComp++)
        {
            tList.getComponentAt(idxComp).addFocusListener(this);
        }
isTableSelected = false;

And here are the implemented methods :

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);
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文