【问题标题】:First Visible Row in CodenameoneCodenameone 中的第一个可见行
【发布时间】:2020-09-03 11:48:22
【问题描述】:

我尝试使用此代码获取 BorderLayout.CENTER 内滚动表中的第一个可见行,但它不起作用,似乎返回的点不反映可见单元格,除非我错过了一种计算,

感谢您的见解,

@Override
protected void onScrollY(int scrollY) {
    super.onScrollY(scrollY); //To change body of generated methods, choose Tools | Templates.
    
    Component c=getComponentAt(50, scrollY);
    if (c instanceof Table){
        System.err.println("table "+getWidth()+" "+getHeight()+" s "+scrollY);
        return;
    }
    Button b=(Button) c;

    System.err.println("c: "+b.getText());
    
    
}

【问题讨论】:

    标签: row codenameone


    【解决方案1】:

    getComponentAt(x,y) 采用绝对(屏幕)坐标。 scrollY 值是该容器中的相对坐标。

    所以你想要的是这样的:

    Component c = getComponentAt(getAbsoluteX()+50, getAbsoluteY() + scrollY)
    

    getComponentAt(x,y) 只会返回可聚焦或已设置为抓取指针事件的组件也毫无价值。如果您只想找到此容器的第一个可绘制的直接子级,并且您使用的是 BoxLayout.Y_AXIS 布局,那么您最好只遍历子级,直到找到一个 y 至少为 scrollY 的子级。

    例如

    Component c = null;
    for (Component child : this) {
        if (child.getY() + child.getHeight() > scrollY) {
            c = child;
            break;
        }
    }
    ....
    

    【讨论】:

      猜你喜欢
      • 2017-02-14
      • 2013-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-13
      • 1970-01-01
      • 2013-09-02
      相关资源
      最近更新 更多