0

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

//列表声明

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

1 回答 1

0

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

于 2013-06-13T12:04:25.697 回答