I want to create text boxes above the header of the grid to be used as a filter boxes and match the width of the columns even when they are resized
https://www.b4x.com/android/forum/threads/implement-tableview-column-resize.49757/post-310809And I still don't even know if there is a way to prevent column resizing
Private Sub SetColumnListeners
Dim jo As JavaObject = TableView1
Dim ColumnList As List = jo.RunMethodJO("getColumns", Null)
For Each Col As JavaObject In ColumnList
Dim Prop As JavaObject = Col.RunMethod("widthProperty",Null)
Dim o As Object = Prop.CreateEventFromUI("javafx.beans.value.ChangeListener","ColumnChanged",Null)
Prop.RunMethod("addListener",Array(o))
Next
End Sub
Private Sub ColumnChanged_Event (MethodName As String, Args() As Object) As Object
Dim Col As JavaObject = Sender
Dim jo As JavaObject = TableView1
Dim ColumnList As List = jo.RunMethodJO("getColumns", Null)
Dim Width As Double = Args(2)
Dim ColNum As Int = ColumnList.IndexOf(Col.RunMethod("getBean",Null))
Log(ColNum & " : " & Width)
End Sub
um.. so you think can be a problem with B4XPages.I haven't tried it in a B4xPages project. Can you upload it so I don't have to create one?
I wouldn't have thought so, but it works in a standard project as is.so you think can be a problem with B4XPages
tableView.widthProperty().addListener(new ChangeListener<Number>()
{
@Override
public void changed(ObservableValue<? extends Number> source, Number oldWidth, Number newWidth)
{
TableHeaderRow header = (TableHeaderRow) tableView.lookup("TableHeaderRow");
header.reorderingProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
header.setReordering(false);
}
});
}
});
public static <S, T> void columnReorder(TableView table, TableColumn<S, T> ...columns) {
table.getColumns().addListener(new ListChangeListener() {
public boolean suspended;
@Override
public void onChanged(Change change) {
change.next();
if (change.wasReplaced() && !suspended) {
this.suspended = true;
table.getColumns().setAll(columns);
this.suspended = false;
}
}
});
}
Private Sub DisableReordering
Dim Jo As JavaObject = TableView1
Dim Header As JavaObject = Jo.RunMethod("lookup",Array("TableHeaderRow"))
Dim Prop As JavaObject = Header.RunMethod("reorderingProperty",Null)
Dim o As Object = Prop.CreateEventFromUI("javafx.beans.value.ChangeListener","HeaderOrder",Null)
Prop.RunMethod("addListener",Array(o))
End Sub
Private Sub HeaderOrder_Event (MethodName As String, Args() As Object) As Object
Dim JO As JavaObject = Sender
Dim Header As JavaObject = JO.RunMethod("getBean",Null)
Header.RunMethod("setReordering",Array(False))
End Sub
Strangely, while the "AddColumnChangedEvent" (I just changed its name) works written right after:It works, but is not great. It flashes a bit.
Root.LoadLayout ("MainPage")
DisableReordering
IT'S GREAT, STEVE!It works, but is not great. It flashes a bit.
Yes, it looks better so (not about the flickering, which is not very "annoying"):crashes, as if the TableView hadn't already been initialized.
Maybe it would be necessary to put that call in the page's Appear event, but it works just adding Sleep (0) right before that.
Private Sub B4XPage_Appear
If Not(mReorderingDisabled) Then
DisableReordering
mReorderingDisabled = True
End If
End Sub