在lwuit中扩展容器时,列表不会滚动

时间:2013-06-06 09:29:40

标签: list scroll containers lwuit

在容器中添加图像时,列表不会滚动。我有一个扩展容器的列表。我使用了两个容器来设置图像字段(左)和文本字段(右)。虽然我正在添加文本字段容器列表滚动正确,但在左侧字段中添加图像时它没有滚动请帮助我。谢谢你的帮助。

//列表声明

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;
        }

1 个答案:

答案 0 :(得分:0)

您正在调用scaled(),这是渲染器中非常缓慢且昂贵的操作,必须非常快。不是个好主意。不确定这是否能解决您的问题,但我建议您调查TRAIL标志是否是导致问题的原因。