### Customized TableView Examples

Sample code snippets on how to customize a tableview.
This project shows a scrollpane with several customized tableviews.
Note:
Customizing a ListView can be done in a similiar way.
`Sub Process_Globals
Private fx As JFX
Private MainForm As Form
'Scrollpane holding the various tableview examples
Private sp As ScrollPane
End Sub`
`Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.Title = "TableView Customized Examples"
MainForm.Show
sp.Initialize("sp")
MainForm.RootPane.AddNode(sp, 10, 10, 250, 500)
CreateTableView1
CreateTableView2
CreateTableView3
CreateTableView4
CreateTableView5
CreateTableView6
' add more
End Sub`
'Standard: Create a TableView with 2 columns, 3 values and totals
`Sub CreateTableView1
Dim tvw As TableView
tvw.Initialize("tvw")
tvw.TooltipText = "Standard: Create a TableView with 2 columns, 3 values and totals"
Dim p As Pane = sp.InnerNode
p.AddNode(tvw, 10, 0, 250, 250)
tvw.SetColumns(Array As String("1/ColA", "1/ColB"))
tvw.SetColumnWidth(0, 100)
tvw.SetColumnWidth(1, 100)
tvw.PrefWidth = 202
tvw.PrefHeight = 200
For i = 1 To 3
Dim x As Double = i
tvw.Items.Add(Array As Object(x, x*x))
Next
Dim totalA, totalB As Double
For Each row() As Object In tvw.Items
If IsNumber(row(0)) Then totalA = totalA + row(0)
If IsNumber(row(1)) Then totalB = totalB + row(1)
Next
tvw.Items.Add(Array As Object("Total", "Total"))
tvw.Items.Add(Array As Object(totalA, totalB))
End Sub`
'Customized: Create a TableView with 2 columns (Label/Label), 3 values and totals
`Sub CreateTableView2
Dim tvw As TableView
tvw.Initialize("tvw")
tvw.TooltipText = "Customized: Create a TableView with 2 columns (Label/Label), 3 values and totals"
Dim p As Pane = sp.InnerNode
p.AddNode(tvw, 10, 250, 250, 250)
tvw.SetColumns(Array As String("2/ColA", "2/ColB"))
tvw.SetColumnWidth(0, 100)
tvw.SetColumnWidth(1, 100)
tvw.PrefWidth = 202
tvw.PrefHeight = 200
For i = 1 To 3
tvw.Items.Add(Array As Object(TableView_AddLabel(i), TableView_AddLabel(i * i)))
Next
Dim totalA, totalB As Double
For Each row() As Object In tvw.Items
Dim l0 As Label = row(0)
Dim l1 As Label = row(1)
If IsNumber(l0.Text) Then totalA = totalA + l0.Text
If IsNumber(l1.Text) Then totalB = totalB + l1.Text
Next
tvw.Items.Add(Array As Object(TableView_AddLabel("Total"), TableView_AddLabel("Total")))
tvw.Items.Add(Array As Object(TableView_AddLabel(totalA), TableView_AddLabel(totalB)))
End Sub`
'Customized: Create a TableView with 2 columns (Label wrapped/Label wrapped), 3 values and totals
`Sub CreateTableView3
Dim tvw As TableView
tvw.Initialize("tvw")
tvw.TooltipText = "Customized: Create a TableView with 2 columns (Label wrapped/Label wrapped), 3 values and totals"
Dim p As Pane = sp.InnerNode
p.AddNode(tvw, 10, 500, 250, 250)
tvw.SetColumns(Array As String("3/ColA", "3/ColB"))
tvw.SetColumnWidth(0, 100)
tvw.SetColumnWidth(1, 100)
tvw.PrefWidth = 202
tvw.PrefHeight = 200
For i = 1 To 3
tvw.Items.Add(Array As Object(TableView_AddLabel(i), TableView_AddLabel(i * i)))
Next
Dim totalA, totalB As Double
For Each row() As Object In tvw.Items
Dim l0 As Label = row(0)
Dim l1 As Label = row(1)
If IsNumber(l0.Text) Then totalA = totalA + l0.Text
If IsNumber(l1.Text) Then totalB = totalB + l1.Text
Next
tvw.Items.Add(Array As Object(TableView_AddLabel2("Total","CENTER"), TableView_AddLabel2("Total","CENTER_RIGHT")))
tvw.Items.Add(Array As Object(TableView_AddLabel2(totalA,"CENTER"), TableView_AddLabel2(totalB,"CENTER_RIGHT")))
End Sub`
'Customized: Create a TableView with 2 columns (Label/TextField), 3 values and totals
`Sub CreateTableView4
Dim tvw As TableView
tvw.Initialize("tvw")
tvw.TooltipText = "Customized: Create a TableView with 2 columns (Label/TextField), 3 values and totals"
Dim p As Pane = sp.InnerNode
p.AddNode(tvw, 10, 750, 250, 250)
tvw.SetColumns(Array As String("4/ColA", "4/ColB"))
tvw.SetColumnWidth(0, 100)
tvw.SetColumnWidth(1, 100)
tvw.PrefWidth = 202
tvw.PrefHeight = 200
For i = 1 To 3
tvw.Items.Add(Array As Object(TableView_AddLabel("Label " & i), TableView_AddField(i * i)))
Next
Dim totalB As Double
For Each row() As Object In tvw.Items
Dim tfB As TextField = row(1)
If IsNumber(tfB.Text) Then totalB = totalB + tfB.Text
Next
tvw.Items.Add(Array As Object(TableView_AddLabel2("Total:","CENTER_RIGHT"), TableView_AddLabel2(totalB,"CENTER_LEFT")))
End Sub`
'Customized: Create a TableView with 1 columns (Image/TextField)
`Sub CreateTableView5
Dim tvw As TableView
tvw.Initialize("tvw")
tvw.TooltipText = "Customized: Create a TableView with 1 columns (Image/TextField)"
Dim p As Pane = sp.InnerNode
p.AddNode(tvw, 10, 1000, 250, 250)
tvw.SetColumns(Array As String("5/ColA", "5/ColB"))
tvw.SetColumnWidth(0, 100)
tvw.SetColumnWidth(1, 100)
tvw.PrefWidth = 202
tvw.PrefHeight = 200
tvw.Items.Add(Array As Object(TableView_AddImage("L.png"), TableView_AddField("L")))
tvw.Items.Add(Array As Object(TableView_AddImage("I.png"), TableView_AddField("I")))
tvw.Items.Add(Array As Object(TableView_AddImage("N.png"), TableView_AddField("N")))
tvw.Items.Add(Array As Object(TableView_AddImage("N.png"), TableView_AddField("N")))
End Sub`
' Customized: Create a TableView with 1 column (CheckBox), 3 rows
`Sub CreateTableView6
Dim tvw As TableView
tvw.Initialize("tvw")
tvw.TooltipText = "Customized: Create a TableView with 1 column (CheckBox), 3 rows"
Dim p As Pane = sp.InnerNode
p.AddNode(tvw, 10, 1250, 250, 250)
tvw.SetColumns(Array As String("6/ColA"))
tvw.SetColumnWidth(0, 200)
tvw.PrefWidth = 202
tvw.PrefHeight = 200
For i = 1 To 3
tvw.Items.Add(Array As Object(TableView_AddCheckBox("CB"&i, "Checkbox " & i)))
Next
End Sub`
' Handle the action from the checkbox event. Important to set the eventname to CB when creating the textbox
`Sub CB_Action
Dim C As CheckBox = Sender
Log(C.Tag)
End Sub`
'
'HELPERS
'
`Sub TableView_AddLabel(labeltext As String) As Label
Dim lbl1 As Label
lbl1.Initialize("")
lbl1.text = labeltext
lbl1.Font = fx.DefaultFont(Rnd(10, 20))
lbl1.TextColor = fx.Colors.From32Bit(Rnd(0x80000000, -1))
Return lbl1
End Sub`
`Sub TableView_AddLabel2(labeltext As String, Alignment As String) As Pane
Dim lbl1 As Label
lbl1.Initialize("")
lbl1.text = labeltext
lbl1.Font = fx.DefaultFont(Rnd(10, 20))
lbl1.TextColor = fx.Colors.From32Bit(Rnd(0x80000000, -1))
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`
`Sub TableView_AddField(fieldtext As String) As TextField
Dim tf As TextField
tf.Initialize("")
tf.text = fieldtext
tf.Style = "-fx-fontsize:12px;"
Return tf
End Sub`
`Sub TableView_AddImage(filename As String) As ImageView
Dim img As ImageView
img.Initialize("")
img.SetImage(fx.LoadImage(File.DirAssets, filename))
Return img
End Sub`
`Sub TableView_AddCheckBox(id As String, fieldtext As String) As CheckBox
Dim cb As CheckBox
' Set the event name to CB. This is being used by the CB_Action
cb.Initialize("CB")
cb.text = fieldtext
cb.Tag = id
cb.Style = "-fx-fontsize:12px;"
Return cb
End Sub`

Changed: , Category: TableView, File: T6C259M1878.htm, ID: 1878