Routine to determine which rows are visible in a TableView/ListView.
Java code (for libraries etc)
The @SuppresWarnings("restriction") is needed as it uses VirtualFlow which is not really a normal thing to use, but as of yet they have not made a public api to return these values.
B4J code for TableView visible items
B4J code for ListView visible items
Screenshot below is an example of what it can be used for.
Java code (for libraries etc)
B4X:
@SuppressWarnings("restriction")
private int first =0;
private int last = 0;
public void getFirstAndLast(TableView<?> t){
TableViewSkin<?> ts = (TableViewSkin<?>) t.getSkin();
VirtualFlow<?> vf = (VirtualFlow<?>)ts.getChildren().get(1);
first = vf.getFirstVisibleCell().getIndex();
last = vf.getLastVisibleCell().getIndex();
}
public int getFirst(){
return first;
}
public int getlast(){
return last;
}
The @SuppresWarnings("restriction") is needed as it uses VirtualFlow which is not really a normal thing to use, but as of yet they have not made a public api to return these values.
B4J code for TableView visible items
B4X:
' t,tvs and vf defined as JavaObject
tvs.InitializeStatic("com.sun.javafx.scene.control.skin.TableViewSkin") ' JavaObject
vf.InitializeStatic("com.sun.javafx.scene.control.skin.VirtualFlow") ' JavaObject
t = table1 ' TableView to look at
tvs = t.RunMethodJO("getSkin",Null) ' get skin from TableView
vf = tvs.RunMethodJO("getChildren",Null).RunMethodJO("get",Array As Object(1)) ' get virtual flow from skin
first = vf.RunMethodJO("getFirstVisibleCell",Null).RunMethod("getIndex",Null) ' get first from virtual flow
last = vf.RunMethodJO("getLastVisibleCell",Null).RunMethod("getIndex",Null) ' get last from virtual flow
Log("First: "& first & " Last: " & last) ' just display values
B4J code for ListView visible items
B4X:
' l,lvs, vf as JavaObject
lvs.InitializeStatic("com.sun.javafx.scene.control.skin.ListViewSkin") ' JavaObject
vf.InitializeStatic("com.sun.javafx.scene.control.skin.VirtualFlow") ' JavaObject
l = list1 ' ListView to look at
lvs = l.RunMethodJO("getSkin",Null) ' get skin from ListView
vf = lvs.RunMethodJO("getChildren",Null).RunMethodJO("get",Array As Object(0)) ' get virtual flow from skin
first = vf.RunMethodJO("getFirstVisibleCell",Null).RunMethod("getIndex",Null) ' get first from virtual flow
last = vf.RunMethodJO("getLastVisibleCell",Null).RunMethod("getIndex",Null) ' get last from virtual flow
Log("First: "& first & " Last: " & last) ' just display values
Screenshot below is an example of what it can be used for.
Attachments
Last edited: