B4J Question Having problems with TableView Column Width Settings

BPak

Active Member
Licensed User
Longtime User
Having problems with TableView Column Width Settings.

In the First Image TV1.png the last column is set at 80.1 and the Columns fit in snugly up against the Vertical ScrollBar. It can be set to 79.0 and fits in and leaves a big margin from the ScrollBar.

In the second Image TV2.png the Last Column width is changed to 80.0 which is LESS than the width used for TV1.png yet the last Column Width blows out well past the Vertical ScrollBar.

The First Column for Date also misbehaves when the Width is changed from 80.0 to 79.0 as it reduces the Column to JUST fit the text into it. Reducing much more than 1 pixel.

Seems like Widths with zero ending do not calculate correctly?

Labels are used in the TableView except for first column which is invisible.

Only noticed this happening since the last update of B4J.

Code used for setting up the TableView:

B4X:
Private Sub SetupTableView
    Dim RList As List
       
    RList.Initialize
    RList.Add("SId")
    RList.Add("Date")
    RList.Add("No")
    RList.Add("Name")
    RList.Add("Odds")
    RList.Add("Base")
    RList.Add("Recoup")
    RList.Add("Bet")
    RList.Add("Div")
    RList.Add("Win")
    RList.Add("Loss")
    RList.Add("Tot. Loss")
    RList.Add("Balance")
   
    EndBetTV.SetColumns(RList)

    EndBetTV.SetColumnVisible(0, False) ' SId
    EndBetTV.SetColumnWidth(1, 80.0)    ' Date
    EndBetTV.SetColumnWidth(2, 30.0)    ' No
    EndBetTV.SetColumnWidth(3, 135.0)    ' Name
    EndBetTV.SetColumnWidth(4, 50.0)    ' Odds
    EndBetTV.SetColumnWidth(5, 50.0)    ' Base
    EndBetTV.SetColumnWidth(6, 60.0)    ' Recoup
    EndBetTV.SetColumnWidth(7, 50.0)    ' Bet
    EndBetTV.SetColumnWidth(8, 50.0)    ' Div
    EndBetTV.SetColumnWidth(9, 55.0)    ' Win
    EndBetTV.SetColumnWidth(10, 55.0)    ' Loss
    EndBetTV.SetColumnWidth(11, 70.1)    ' TotLoss
    EndBetTV.SetColumnWidth(12, 80.0)    ' Balance
   
    ' do not want sorting as RowIndex is used throught the calcs
    For i= 1 To 12
        EndBetTV.SetColumnSortable(i, False)
    Next
   
    RList.Clear
End Sub

Code Used to fill the TableView:
B4X:
Public Sub LoadEndBetsTable(SQL As SQL, Query As String, StringArgs() As String, Limit As Int, _
    TableView1 As TableView)

    TableView1.Items.Clear

    Dim cur As ResultSet
    If StringArgs = Null Then
        Dim StringArgs(0) As String
    End If
    cur = SQL.ExecQuery2(Query, StringArgs)
   
    Do While cur.NextRow
        Dim values(cur.ColumnCount) As Object
        For col = 0 To cur.ColumnCount - 1
            Select col
                Case 0
                    values(col) = cur.GetString2(col)
                Case 1, 3
                    Dim lbl As Label
                    lbl.Initialize("")
                    lbl.PrefWidth = TableView1.GetColumnWidth(col)
                    lbl.Style = "-fx-font-family: Tahoma; -fx-font-size: 14px;"        ' Left-align
                    lbl.Text = cur.GetString2(col)
                    values(col) = lbl
                Case 2, 4, 5, 6, 8, 9, 10, 11, 12
                    Dim lbl As Label
                    lbl.Initialize("")
                    lbl.PrefWidth = TableView1.GetColumnWidth(col)
                    lbl.Style = "-fx-font-family: Tahoma; -fx-font-size: 14px; -fx-alignment: CENTER;"    ' Center
                    lbl.Text = cur.GetString2(col)
                    values(col) = lbl
                Case 7
                    Dim lbl As Label
                    lbl.Initialize("")
                    lbl.PrefWidth = TableView1.GetColumnWidth(col)
                    lbl.Style = "-fx-font-family: Tahoma; -fx-font-size: 14px; -fx-font-weight: bold; -fx-alignment: CENTER;"    ' Center
                    lbl.Text = cur.GetString2(col)
                    values(col) = lbl
            End Select
        Next
        TableView1.Items.Add(values)
        If Limit > 0 AND TableView1.Items.Size >= Limit Then Exit
    Loop
    cur.Close   
End Sub
 

Attachments

  • tv1.PNG
    tv1.PNG
    80.5 KB · Views: 530
  • tv2.PNG
    tv2.PNG
    83.5 KB · Views: 618

Daestrum

Expert
Licensed User
Longtime User
Have you tried re-sizing from col12 to col1.
I know it sounds odd, but as you change column widths from the left, all the columns to the right move, maybe introducing an error.
 
Upvote 0

BPak

Active Member
Licensed User
Longtime User
Daestrum: Have tried changing columns in different places and they all seem to give different results. Actually the TableView measurements are Loaded in the Initialise Sub.

EreL: Attached is the example. I have used the Zip in B4J to get the Files.
Also added the Database into the Zip which you can place in the Object Folder.

Thank you for looking at this problem for me.
 

Attachments

  • PBEx.zip
    10.6 KB · Views: 381
Upvote 0
Top