B4J Question TableView Content Resize

BarryW

Active Member
Licensed User
Longtime User
Hi.

After loading my data on tableview ( 20 to 30 columns all needed ) it resize the columns width into equal based on numbers of column.

But when i double click the column header separator after loading the data it auto size the width of that column based on its content. Is there something like that to do it tru codes.

Tnx.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use this code to call the private method that auto-resizes a column:
B4X:
Sub ResizeToFit(tv As TableView, ColumnIndex As Int)
   Dim tvjo As JavaObject = tv
   Dim r As Reflector
   r.Target = tvjo.RunMethod("getSkin", Null)
   r.RunMethod4("resizeColumnToFitContent", Array(tvjo.RunMethodJO("getColumns", Null).RunMethod("get", Array(ColumnIndex)), -1), _
      Array As String("javafx.scene.control.TableColumn", "java.lang.int"))
End Sub

Depends on JavaObject and jReflection libraries.
 
Upvote 0

BarryW

Active Member
Licensed User
Longtime User
I got this error when i used this code

B4X:
    java.lang.NullPointerException
    at com.sun.javafx.scene.control.skin.TableViewSkin.resizeColumnToFitContent(TableViewSkin.java:257)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at anywheresoftware.b4j.agraham.reflection.Reflection.runmethod(Reflection.java:168)
    at anywheresoftware.b4j.agraham.reflection.Reflection.RunMethod4(Reflection.java:932)
    at felco.prj.dar.review._resizetofit(review.java:254)
    at felco.prj.dar.review._btnload_action(review.java:102)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
    at anywheresoftware.b4a.BA$2.run(BA.java:165)
    at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$149(WinApplication.java:191)
    at java.lang.Thread.run(Thread.java:745)
 
Upvote 0

BarryW

Active Member
Licensed User
Longtime User
Here is my project. I create a sample because my actual project connects to a database but they have same error.

Try to click the load button twice.
 

Attachments

  • Table.zip
    317.3 KB · Views: 510
Upvote 0
Top