B4J Question Change TabPane vertical Label Orientation

hi all
how to Change TabPane vertical Label Orientation like this image ?

gWDXh.png


sorry for my bad English
 

jmon

Well-Known Member
Licensed User
Longtime User
Actually it's possible, but be warned that this is pure cheating! Workaround at it's best :p
Capture.JPG


The way I do it is by setting a label as the graphic of each tab. Then I set a graphic to that label. Then remove the text of the tab, and set the text in the label instead. Now the problem is that Javafx still thinks tabs are not rotated, so width & height are inverted (only the label is rotated inside the tab graphic). I wrote the code for you (need javaObject):
B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Main") 'Load the layout file.

    HoryzontalTabs

    MainForm.Show
End Sub

Sub HoryzontalTabs
    Dim TabWidth As Double = 150
    Dim TabHeight As Double = 48
    Dim TabImageSize As Double = 48

    SetTabsSettings(tp1, TabWidth, TabHeight, "LEFT") 'Also works for RIGHT

    Dim graphic As Image
    graphic.InitializeSample(File.DirAssets, "general.png", TabImageSize, TabImageSize)
    SetTabGraphic(tab1, "General", graphic, TabWidth, TabHeight, "CENTER_LEFT") 'try alignment = "CENTER", or "CENTER_RIGHT"

    Dim graphic As Image
    graphic.InitializeSample(File.DirAssets, "font.png", TabImageSize, TabImageSize)
    SetTabGraphic(tab2, "Select Fonts", graphic, TabWidth, TabHeight, "CENTER_LEFT")

    Dim graphic As Image
    graphic.InitializeSample(File.DirAssets, "settings.png", TabImageSize, TabImageSize)
    SetTabGraphic(tab3, "Settings", graphic, TabWidth, TabHeight, "CENTER_LEFT")

End Sub

Sub SetTabsSettings(tp As TabPane, Width As Double, Height As Double, TabsSide As String)
    tp.SetSide(TabsSide)
    Dim tpJo As JavaObject = tp
    tpJo.RunMethod("setTabMinWidth", Array(Height))
    tpJo.RunMethod("setTabMaxWidth", Array(Height))
    tpJo.RunMethod("setTabMinHeight", Array(Width))
    tpJo.RunMethod("setTabMaxHeight", Array(Width))
End Sub

Sub SetTabGraphic(Page As TabPage, Text As String, Graphic As Image, Width As Double, Height As Double, Alignment As String)
    Dim lJo, PageJo As JavaObject
    PageJo = Page
    Page.Text = ""

    Dim l As Label
    l.Initialize("")
    l.Text = Text
    l.Alignment = Alignment
    lJo = l

    If Graphic.IsInitialized Then
        Dim iv As ImageView
        iv.Initialize("")
        iv.SetImage(Graphic)
        iv.Width = Graphic.Width
        iv.Height = Graphic.Height
        lJo.RunMethod("setGraphic", Array(iv))
    End If

    lJo.RunMethod("setMaxHeight", Array(Height))
    lJo.RunMethod("setMinWidth", Array(Width))
    lJo.RunMethod("setRotate", Array(90.0))
    lJo.RunMethod("setContentDisplay", Array("LEFT"))
    PageJo.RunMethod("setGraphic", Array(l))
End Sub

It works for both "LEFT" & "RIGHT". Check the example attached.
 

Attachments

  • HoryzontalTabs.zip
    8.3 KB · Views: 318
Last edited:
Upvote 0
Top