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