B4J Question TableView - Header Alignment

RichardN

Well-Known Member
Licensed User
Longtime User
I am attempting to left/center align the headers of a TableView. There seems to be no core method and I have tried the CSS method without success. I have looked at the various (few) examples on the forum but none seem to work as the IDE reports that the CSS file is not being parsed correctly. As a stranger to CSS I need some assistance please:

B4X:
Private Col As Int
TableView1.SetColumns(Array As String("Date","Type","Item","Credit","Debit","Balance","Reconciled","OK"))
        
    For Col = 0 To TableView1.ColumnsCount -1
        SetColumnStyle(Col,File.GetUri(File.DirAssets, "mystyle.css"))
        TableView1.SetColumnSortable(Col,False)
    Next

Using 'mystyle.css'
B4X:
.my-special-column-style .label {
  -fx-alignment: center-left;
}
 

RichardN

Well-Known Member
Licensed User
Longtime User
You are correct Erel, I am attempting to use that Sub:
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

The examples on the page you have quoted appear confined to changing the Table Cell properties of width, height, alignment and back-color. I can see no code that changes the alignment of the headers. What style string is used to manipulate TableView header alignment?
 
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
<<Specific column?>> No, I actually only need to set the header alignment property for all columns to 'Left' once at the beginning of the project.

Is it possible to do that globally for a TableView using the jo.Runmethod without using CSS?
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Small example (although css file would be easier)
B4X:
Sub Process_Globals
 Private fx As JFX
 Private MainForm As Form
 Private TableView1 As TableView
End Sub
Sub AppStart (Form1 As Form, Args() As String)
 MainForm = Form1
 MainForm.RootPane.LoadLayout("tv1") 'Just a default tableview with 3 cols
 MainForm.Show
 justifyTableHeaders(TableView1,"center_left")
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
 Return True
End Sub
Sub justifyTableHeaders(theTableView As JavaObject,setTo As String)
 Dim headers,iter As JavaObject
 headers = theTableView.RunMethodjo("lookupAll",Array(".table-view .column-header .label"))
  iter = headers.runmethod("iterator",Null)
 Do While 1=1
  Try
   CSSUtils.SetStyleProperty(iter.RunMethod("next",Null),"-fx-alignment",setTo)
  Catch
   Exit
  End Try
 Loop
End Sub
 
Upvote 0
Top