Package totalcross.ui

Class ColorList

  • All Implemented Interfaces:
    Scrollable

    public class ColorList
    extends ListBox
    Implements a ListBox where colors can be choosen from. The only functional methods are setColors, getSelectedItem and getSelectedColor. Next an example of how to use this class as a combobox color chooser:
     add(foreCombo = new ComboBox(new ColorList()), CENTER, BOTTOM);
     
    Consider using ColorChooserBox instead.
    See Also:
    totalcross.ui#ColorChooserBox
    • Constructor Detail

      • ColorList

        public ColorList()
    • Method Detail

      • setColors

        public void setColors​(int[] newColors)
        Sets the colors that will be displayed.
      • drawItem

        protected void drawItem​(Graphics g,
                                int index,
                                int dx,
                                int dy)
        Description copied from class: ListBox
        You can extend ListBox and overide this method to draw the items
        Overrides:
        drawItem in class ListBox
      • drawSelectedItem

        protected void drawSelectedItem​(Graphics g,
                                        int index,
                                        int dx,
                                        int dy,
                                        int w)
        Description copied from class: ListBox
        You can extend ListBox and overide this method to draw the items
        Overrides:
        drawSelectedItem in class ListBox
      • drawCursor

        protected void drawCursor​(Graphics g,
                                  int sel,
                                  boolean on)
        Description copied from class: ListBox
        This method is used to draw the cursor around the desired item
        Overrides:
        drawCursor in class ListBox
      • getPreferredWidth

        public int getPreferredWidth()
        Description copied from class: ListBox
        Returns the preferred width, ie, the size of the largest item plus the size of the scrollbar.
        Overrides:
        getPreferredWidth in class ListBox
      • getItemWidth

        protected int getItemWidth​(int index)
        Description copied from class: ListBox
        Returns the width of the given item index with the current fontmetrics. Note: if you overide this class you must implement this method.
        Overrides:
        getItemWidth in class ListBox
      • getSelectedItem

        public java.lang.Object getSelectedItem()
        Returns the selected Item object, or a black Item representing the black color if none was selected. From the Item you can retrieve the color as int. Use the getSelectedColor method to retrieve the color directly.
        Overrides:
        getSelectedItem in class ListBox
      • getSelectedColor

        public int getSelectedColor()
        Returns the selected color or black if no one is selected.