Question

I am making a list that has persons and every ones rate as a cell background the list gives every cell the same rate background but when scroll the list up or down the cell that I'm dragging take it's real rate background but other cells stay the same rate background image I'm using nokia s40 full touch emulator This is the code that I'm using for the cell renderer

    list.setRenderer(new ListCellRenderer() {

        public Component getListFocusComponent(List list) {
            // TODO Auto-generated method stub
            return null;
        }

        public Component getListCellRendererComponent(List list,
                Object value, int index, boolean isSelected) {
            String rate = "";

            rate = Transportation.getDriverRate(value.toString(),
                    CityListForm.selectedCity);
            rate = (Integer.parseInt(rate)) > 25 ? "" + 5 : ""
                    + Integer.parseInt(rate) / 5;
            rate = "/" + rate + ".png";
            Image image = null;
            Label label = null;
            try {

                image = (Image.createImage(rate));
                System.out.println(rate);
            } catch (IOException e) {
                e.printStackTrace();
            }
            label = new Label();

            label.getStyle().setBgImage(image);
            label.setText(value.toString());
            label.getStyle().setAlignment(RIGHT);
            label.setTextPosition(RIGHT);
            Style style = label.getStyle();
            style.setBgColor(16777215);
            style.setFgColor(0);

            label.setPreferredH(42);
            return label;
        }
    });
Was it helpful?

Solution

Use List.setMutableRendererBackgrounds(true);

OTHER TIPS

thnx for the answer i solved it by making a container and butting two labels inside it one for the value and the other for the rate icon and give the container a layout and return the container in the getListCellRendererComponent() method

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top