B4J Question CSS for tableview in code?

Patent

Member
Licensed User
Longtime User
Hi,

want to do the folowing .css-code in B4J code: (to change the hight of the tableview-lines during runtime)

.table-row-cell {
-fx-cell-size: 12px;
}


mytableview.Style ="-fx-cell-size: 12px;" will not work

any Suggestions?
thanks
 

stevel05

Expert
Licensed User
Longtime User
Getting a specific cell or row does not appear to be simple.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
The OP want's to change the height at runtime, you would have to get the cell / row to change the styleclass for it to work. It would be nice if there were a simple way to do it.
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
A tested solution using a JavaObject:

B4X:
' Set the height of a tableview row in px. Default is 24
' Ref: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/TableView.html#setFixedCellSize-double-
' Example: SetTableViewRowHeight(TableView1, 48)
Sub SetTableViewRowHeight(tv As TableView, h As Double)
    Dim joTV As JavaObject = tv
    joTV.RunMethod("setFixedCellSize",Array(h))
End Sub
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
That's good, it sets the height of all rows to the same value. Looking at the original question again, that might be the answer. I read it as the OP was trying to set the size of one row.
 
Upvote 0

Patent

Member
Licensed User
Longtime User
Thank you guys for brainstroming!:)
Thanks rwblinn. Works great. Was to blind to find the right java-method.:cool:

To contribute also a little, maybe useful for others to easy customize a tableview, a summary of a lot:

B4X:
' assuming, there is a mytableview1 existing:

'Style it:
SetColumnStyle(mytableview1, 0, "-fx-text-fill: black; -fx-font-weight: bold; -fx-alignment: CENTER_LEFT;")
SetColumnStyle(mytableview1, 1, "-fx-text-fill: blue; -fx-font-weight: bold; -fx-alignment: CENTER_RIGHT;")

'Change row and text height (size in px):
mytableview1.Style="-fx-font-size: " & size & "px;"
SetTableViewRowHeight(mytableview1, size+6)



B4X:
Sub SetColumnStyle(tv As TableView, ColumnIndex As Int, Style As String, h as DOUBLE)
   Dim jo As JavaObject = tv
   jo.RunMethodJO("getColumns", Null).RunMethodJO("get", Array(ColumnIndex)).RunMethod("setStyle", Array(Style))
End Sub

Sub SetTableViewRowHeight(tv As TableView, h As Double)
  Dim jo As JavaObject = tv
  jo.RunMethod("setFixedCellSize",Array(h))
End Sub
 
Upvote 0
Top