简体   繁体   中英

list does not scroll while extending container in lwuit

List does not scroll while adding images in container. I have a list that extends container. I have used two containers for setting image field(left) and text filed(right). while I am adding text filed container list scrolls properly but while adding images in left field it did not scroll please help me . Thank you for your help.

//List declaration

orgNames = new List(tempName);
            WidgetRenderer listCheckBoxRenderer = new WidgetRenderer();
            orgNames.setListCellRenderer(listCheckBoxRenderer);                 

            orgNames.setFixedSelection(List.FIXED_TRAIL);
            organizationDetailsForm.addComponent(orgNames);
            OrganizationNameListener orgNameList = new OrganizationNameListener();
            orgNames.addActionListener(orgNameList);

//List renderer class

class WidgetRenderer extends Container implements ListCellRenderer {
        private Image[] images;
        private Button orgImgButton;
        private Image orgImg;
        private Container contImage, contDet;
        private Label orgNameLabel, locationLabel, ratingLabel;

        public WidgetRenderer() {
            super();
            try {
                setLayout(new BorderLayout());
                contDet = new Container(new BoxLayout(BoxLayout.Y_AXIS));
                contImage = new Container();
                contDet.setScrollableY(true);
                contImage.setScrollable(true);
                contDet.setScrollable(true);
                contImage.setScrollable(true);
                contDet.setSmoothScrolling(true);
                contImage.setSmoothScrolling(true);
                setScrollable(true);
                setScrollableY(true);           

                orgImgButton = new Button();
                orgNameLabel = new Label();

                locationLabel = new Label();
                Style orgStyle = new Style();
                Style locStyle = new Style();
                Font font = Font.createSystemFont(Font.FACE_MONOSPACE,
                        Font.STYLE_BOLD, Font.SIZE_MEDIUM);
                orgStyle.setFont(font);
                orgNameLabel.setSelectedStyle(orgStyle);
                orgNameLabel.setPressedStyle(orgStyle);
                orgNameLabel.setUnselectedStyle(orgStyle);
                Font font1 = Font.createSystemFont(Font.FACE_MONOSPACE,
                        Font.STYLE_PLAIN, Font.SIZE_SMALL);
                locStyle.setFont(font1);

                locationLabel.setSelectedStyle(locStyle);
                locationLabel.setPressedStyle(locStyle);
                locationLabel.setUnselectedStyle(locStyle);
                ratingLabel = new Label();
                contImage.addComponent(orgImgButton);
                contDet.addComponent(orgNameLabel);
                contDet.addComponent(locationLabel);
                addComponent(BorderLayout.WEST, contImage);
                addComponent(BorderLayout.CENTER, contDet);
            } catch (Exception ex) {
                System.out.println("ex" + ex.getMessage());
            }
        }

        public Component getListCellRendererComponent(List list, Object value,
                int index, boolean isSelected) {
            // System.out.println("adding names & loc");
            setFocus(isSelected);
            for (int i = 0; i < list.size(); i++) {
                if (index == i) {
                    orgNameLabel.setText(tempName[i]);
                    locationLabel.setText(districtDesc[i] + "," + townDesc[i]);
                    orgImgButton.setIcon(DefaultLayout.CreateScaledImage(loadImage(thumbnailURL), DefaultLayout.screenWidth()*10/100, DefaultLayout.screenHeight()*9/100));
                }
            }

            if (isSelected) {
                getStyle().setBgColor(0x00BFFF);
                getStyle().setBgTransparency(100);
            } else {
                getStyle().setBgTransparency(30);
            }
            return this;
        }

You are invoking scaled() which is a VERY slow and expensive operation within a renderer which must be REALLY fast. Not a good idea. Not sure if that answers your issue but I suggest investigating whether the TRAIL flag is the cause of your issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM