Package totalcross.ui

Class AlignedLabelsContainer


  • public class AlignedLabelsContainer
    extends Container
    AlignedLabelsContainer is a Container used to align all controls to the maximum width of a set of labels. You can define the label alignment. The controls that you add to this container are placed at the right of the labels. Here's a sample of how to use it:
     String[] labels =
     {
        "Name",
        "Born date",
        "Telephone",
        "Address",
        "City",
        "Country",
        "",
     };
     AlignedLabelsContainer c = new AlignedLabelsContainer(labels);
     c.setBorderStyle(BORDER_LOWERED);
     c.labelAlign = RIGHT;
     c.foreColors = new int[]{Color.RED,Color.BLACK,Color.BLACK,Color.BLACK,Color.BLACK,Color.BLACK,Color.BLACK,};
     c.setInsets(2,2,2,2);
     c.childrenFont = font;    // but controls are normal
     add(c,LEFT+2,TOP+2,FILL-2,PREFERRED+4);
     for (int i =0; i < labels.length-2; i++)
        c.add(new Edit(),LEFT+2,AFTER+(i==0?2:0));
     c.add(new ComboBox(new String[]{"Brazil","France"}),LEFT+2,AFTER);
     c.add(new Button("Insert data"),RIGHT,SAME);
     c.add(new Button("Clear data"),RIGHT,AFTER,SAME,PREFERRED);
     
    Since:
    TotalCross 1.01
    • Field Detail

      • labels

        protected java.lang.String[] labels
        The label captions.
      • widths

        protected int[] widths
        The computed widths for the labels.
      • childrenFont

        public Font childrenFont
        Sets this member to the font you want to set to the controls that are added to this container.
        Since:
        TotalCross 1.25
      • foreColors

        public int[] foreColors
        Sets an array with the same number of labels and the colors you want to show for each label. If the number of labels differs, you will get an exception. It can be used to hide a label: just set its foreground color to the background color.
        Since:
        TotalCross 1.2
    • Method Detail

      • setLabels

        public void setLabels​(java.lang.String[] labels,
                              int vgap)
        Sets the labels and the extra gap between rows (which may be 0).
        Parameters:
        labels - The strings that represents the labels. You may pass null, but be sure to call setLabels() again to set the labels with a valid value.
        vgap - The extra gap between rows. May be negative.
        Since:
        TotalCross 1.2
        See Also:
        AlignedLabelsContainer(String[]), AlignedLabelsContainer(String[], int)
      • onFontChanged

        public void onFontChanged()
        Called after a setFont()
        Overrides:
        onFontChanged in class Control
      • add

        public void add​(Control c)
        Since this is an AlignedLabelsContainer, use this to add a label.
        Overrides:
        add in class Container
      • setInsets

        public void setInsets​(int left,
                              int right,
                              int top,
                              int bottom)
        Sets the insets value to match the given ones.
        Overrides:
        setInsets in class Container
        Parameters:
        left - The left border value.
        right - The right border value.
        top - The top border value.
        bottom - The bottom border value.
      • getPreferredWidth

        public int getPreferredWidth()
        Returns the preferred width of this control.
        Overrides:
        getPreferredWidth in class Control
        Returns:
        The preferred width of this control.
      • getPreferredHeight

        public int getPreferredHeight()
        Returns the preferred height of this control.
        Overrides:
        getPreferredHeight in class Control
        Returns:
        The preferred height of this control.
      • onPaint

        public void onPaint​(Graphics g)
        Draws the border (if any).
        Overrides:
        onPaint in class Container
        Parameters:
        g - The graphics object for drawing.
        See Also:
        Graphics
      • getLineY

        public int getLineY​(int line)
        Given a line (staring from 0), returns the y position. Can be used to easily align the controls. Note that the line number may be greater than the number of assigned Labels.
         add(chCasado = new Check("Married"),LEFT,getLineY(4)+2);
         
        Since:
        TotalCross 1.14
      • getLineHeight

        public int getLineHeight()
        Returns the height of a line.
        Returns:
        The height of a line.
        Since:
        TotalCross 1.14
      • getLeftInset

        public int getLeftInset()
        Returns the left inset. To be able to center a control, you have to do like this:
         control.setRect(CENTER-getLeftInset()/2,...);
         
        Returns:
        The left inset.