### Set Cell Alignment

To set the cell alignment of a TableView, two options (so far):
Standard TableView using API Methods (requires the JavaObject library)
'Set the columnstyle of a specific TableView Column
`Sub SetColumnStyle(TblView As TableView, ColumnIndex As Int, Style As String)
Dim joTblView As JavaObject = TblView
joTblView.RunMethodJO("getColumns", Null).RunMethodJO("get", Array(ColumnIndex)).RunMethod("setStyle", Array(Style))
End Sub`
CSS Reference
https://docs.oracle.com/javase/8/javafx/api/javafx/scene/doc-files/cssref.html
then look for -fx-alignment as an example of aligning the cell content.
Example Aligning Cell Content
SetColumnStyle(TableView1, 0, "-fx-alignment: CENTER;")
SetColumnStyle(TableView1, 1, "-fx-alignment: CENTER-RIGHT;")
Standard TableView using a List
Get the List of rows with TableView.Items.
Modify the relevant cell and set the items again.
Note that the table position will be lost.
Customized TableView instead of Standard TableView
Instead of adding strings as items add Label Controls.
For the Label Control, the properties can be set.
Example Subroutine of adding a Pane with one Label (with Textcolor Blue) (requires the JavaObject library).
'Parameter:
'Text to display in the Label
'Alignment of the text, CENTER, CENTER_LEFT, CENTER_RIGHT etc.
'See Reference for Values https://docs.oracle.com/javafx/2/api/javafx/geometry/Pos.html
`Sub TableView_AddLabel(labeltext As String, Alignment As String) As Pane
Dim lbl1 As Label
lbl1.Initialize("")
lbl1.text = labeltext
lbl1.TextColor = fx.Colors.Blue
Dim pn1 As AnchorPane
pn1.Initialize("")
pn1.AddNode(lbl1, 0, 0, -1, -1)
pn1.FillHorizontally(lbl1, 0, 0)
Dim jo1 = lbl1 As JavaObject
jo1.RunMethod("setAlignment", Array As Object(Alignment))
Return pn1
End Sub`
Example adding two Labels with Text centered (included in a Pane) to the TableView Row:
TableView1.Items.Add(Array As Object(TableView_AddLabel("Label 1", "CENTER"), TableView_AddLabel("Label 2", "CENTER")))
Get the Cell Content
To get the content of a cell, following code is required - because each cell content is a Pane with a Label (or in other words, the Pane has one Node being a Label):
`Sub TableView1_SelectedCellChanged (RowIndex As Int, ColIndex As Int, Cell As Object)
Dim p As Pane = Cell
Dim l As Label = p.GetNode(0)
Log(l.Text)
End Sub`

Changed: , Category: TableView, File: T6C259M1895.htm, ID: 1895