B4J Question [B4X] [SOLVED] Change width of Specific Item at PreferencesDialog

Magma

Expert
Licensed User
Longtime User
Hi there...

1) is it possible to change the width of fields,combo,etc or from a specific item better..



2) Is it possible - to automatic scroll when changing focus-field (when pressing enter key -->goes at the next field - but not scrolling at it) - not after validation but the time of inserting values... ?

You can check my solutions here...

Thanks in advance
 
Last edited:

Magma

Expert
Licensed User
Longtime User
tried that... but i can't even get the size of customlistview ... :-( ....i am pointing to nothing
B4X:
Private Sub SetWidthItem (Pref As PreferencesDialog, Key As String, wwidth As Double)
    For i = 0 To Pref.CustomListView1.Size - 1
        Log(i)
        Dim pi As B4XPrefItem = prefdialog.CustomListView1.GetValue(i)
        Log(pi.Key)
        If pi.Key = Key Then
            Pref.CustomListView1.GetPanel(i).GetView(1).Width=wwidth
        End If
    Next
End Sub
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
Well after hours of searching-trying found "HALF" solution - need a trick and may be it's a new question "how to refresh 'right' prefdialog"

Well... what i achieved...
B4X:
Private Sub SetWidthItem (Pref As PreferencesDialog, Key As String, wwidth As Double) 'Changes the Width of combo.. etc
    For i = 0 To Pref.PrefItems.Size - 1
        Dim pi As B4XPrefItem = Pref.PrefItems.Get(i)
        If pi.key = Key Then
        Dim oldx As Double=Pref.CustomListView1.GetPanel(i).GetView(1).Left
        Dim oldw As Double=Pref.CustomListView1.GetPanel(i).GetView(1).width
        Pref.CustomListView1.GetPanel(i).GetView(1).Left=(oldx + oldw)-wwidth
        Pref.CustomListView1.GetPanel(i).GetView(1).width=wwidth
        End If
    Next
End Sub

Private Sub SetAlignmentItem (Pref As PreferencesDialog, Key As String, aligntext As String) 'not works - i wanna at number fields text to be at right side...
    For i = 0 To Pref.PrefItems.Size - 1
        Dim pi As B4XPrefItem = Pref.PrefItems.Get(i)
        If pi.key = Key Then
        Pref.CustomListView1.GetPanel(i).GetView(1).SetTextAlignment("CENTER", aligntext)
        End If
    Next
End Sub


Private Sub SetDisableItem (Pref As PreferencesDialog, Key As String, disable As Boolean) ' This works very good - suprisely..
    For i = 0 To Pref.PrefItems.Size - 1
        Dim pi As B4XPrefItem = Pref.PrefItems.Get(i)
        If pi.key = Key Then
        Pref.CustomListView1.GetPanel(i).GetView(0).Enabled=disable
        End If
    Next
End Sub

'All can be run at..
Private Sub PrefDialog_BeforeDialogDisplayed (Template As Object)

'for example:
    SetDisableItem(prefdialog,"idsyn",False)
    SetAlignmentItem(prefdialog,"idsyn","RIGHT") '  --->not works
    SetAlignmentItem(prefdialog,"codesyn","RIGHT") '  --->not works
    SetWidthItem(prefdialog,"howpay",300dip)

any help will be appreciated
"after 1 day - 24 hours... found solutions..."

1. Make alignment working (YES!)
2. Width setting with first loading of perfdialog... (now works - after second show...) :-( (FOUND tricky SOLUTION)
3. Is it possible - to automatic scroll when changing focus-field (when pressing enter key -->goes at the next field - but not scrolling at it) - not after validation but the time of inserting values... ? (have in mind TAB works... only Enter key not 'scrolling' at next field) (FOUND SOLUTION)

Thanks in advance
 
Last edited:
Upvote 0

Magma

Expert
Licensed User
Longtime User
About scrolling / changing to next field with pressing enter founds oparra's old solution for trapping keys at (the form) not need to add it for every field!... and use robot to send key...

B4X:
'name it ClassKeyborad.bas (class)
Sub Class_Globals
    Private fx As JFX
    Private mParent As Object
    Private sendk As AWTRobot
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize ( Parent As Object )
    mParent = Parent
End Sub

Public Sub Enter2TAB(ctl As Object)
    Dim r As Reflector
    r.Target = ctl
    r.AddEventFilter("keypressed","javafx.scene.input.KeyEvent.KEY_PRESSED")
End Sub

Private Sub KeyPressed_Filter (e As Event)
    Dim jo As JavaObject = e
    Dim keycode As String = jo.RunMethod("getCode", Null)
    'Log(keycode)
    If keycode = "ENTER" Then
        e.Consume
        sendk.RobotKeyPressByKeyCode(9)
    End If
End Sub

Need to add at every page will be used

at b4xpage_created:
B4X:
    ClassKeyborad1.Enter2TAB(B4XPages.GetNativeParent(Me).RootPane)

and:
B4X:
Public Sub Initialize As Object
    ClassKeyborad1.Initialize(Me)
    Return Me
End Sub

at b4x main page (B4XPage_Created ):
B4X:
    ClassKeyborad1.Initialize(Me)


works very good !
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
For showing b4xpreferencesdialog with changed width and alignments...

Found this tricky solution:
B4X:
    prefdialog.ShowDialog(Options1, "OK", "CANCEL") 'add this line
    Sleep(0) 'add this line
    Wait For (prefdialog.ShowDialog(Options1, "OK", "CANCEL")) Complete (Result As Int)
...

works for now ... :-(
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
Setting Alignment of B4xPreferencesDialog TextField Completed !! found a simple solution...

Actually with this trick you can set alignment at b4xfloattextfield at B4J... and seems works !

B4X:
Private Sub SetAlignmentItem (Pref As PreferencesDialog, Key As String, aligntext As String)
    For i = 0 To Pref.PrefItems.Size - 1
        Dim pi As B4XPrefItem = Pref.PrefItems.Get(i)
        If pi.key = Key And pi.ItemType=Pref.TYPE_TEXT Or pi.ItemType=Pref.TYPE_NUMBER Then

            #If B4A
            Dim ft As B4XFloatTextField = Pref.CustomListView1.GetPanel(i).GetView(0).Tag            
            ft.TextField.SetTextAlignment("CENTER", aligntext)
            #end if
            #if B4J
            Dim ft As B4XFloatTextField = Pref.CustomListView1.GetPanel(i).GetView(0).tag
            CSSUtils.SetStyleProperty(ft.TextField.As(TextField), "-fx-alignment", aligntext)
            #End If

        End If
    Next
End Sub

use it like this:
SetAlignmentItem(prefdialog,"codesyn","CENTER-RIGHT")
 
Upvote 0

mfdlfs

New Member
Hi, I am glad that I found your solution for resizing PD items, but when I tried to use "SetWidthItem" I got an "IndexOutOfBoundsException" at "Dim oldx As Double=Pref.CustomListView1.GetPanel(i).GetView(1).Left" statement. Debug shows pref.customlistview1 has size of 0 (no panels), in my case I would like to change a shortoption that is the third added object. Any help is appreciated. Thanks.
B4X:
    PD.AddSeparator("Text")
    PD.AddNumericRangeItem("ItemQty", "Qty", 0, 10, 1)
    Dim ls As List
    ls.Initialize
    ls.AddAll(Array As String("opt 1", "opt 2", "opt 3"))
    PD.AddShortOptionsItem("MotiveID", "Motive", ls)
    SetWidthItem(PD, "MotiveID", 180dip)
 
Upvote 0

Magma

Expert
Licensed User
Longtime User

B4X:
'All can be run at..
Private Sub PrefDialog_BeforeDialogDisplayed (Template As Object)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…