增加tableView blackberry中的标签字体

时间:2014-04-16 08:52:50

标签: blackberry font-size labelfield

我试图增加tableView中插入的标签中的字体,但以下代码没有任何作用,它们就像我们只能影响Label的文本或背景颜色。

这就是我填充tableView的方式,我为每个Label使用了4种不同的方法,但没有一种方法可以工作!

  private void createTableView() {

    // Initialize the model if it has not yet been loaded
    _tableModel = new SortedTableModel(StringComparator.getInstance(true),
            0);

    // Populate the list
    for (int i = 0; i < 2; i++) {

        _tableModel.addRow(new Object[] { "" });
    }

    // Create and apply style
    RegionStyles style = new RegionStyles(BorderFactory.createSimpleBorder(
            new XYEdges(1, 1, 1, 1), Border.STYLE_SOLID), null, null, null,
            RegionStyles.ALIGN_LEFT, RegionStyles.ALIGN_TOP);

    // Create the view and controller
    TableView tableView = new TableView(_tableModel);
    TableController tableController = new TableController(_tableModel,
            tableView);

    // Set the behaviour of the controller when a table item is clicked

    tableView.setController(tableController);
    tableController.setFocusPolicy(0);

    // Create a DataTemplate that suppresses the third column
    DataTemplate dataTemplate = new DataTemplate(tableView, 1, 2) {
        /**
         * @see DataTemplate#getDataFields(int)
         */
        public Field[] getDataFields(int modelRowIndex) {

            Field[] fields = new Field[2];

            if (modelRowIndex == 0) {
                fields[0] = new LabelField("  Company name") {
                    public void paint(Graphics graphics) {
                        Font font = Font.getDefault().derive(Font.PLAIN, 6,
                                Ui.UNITS_pt);
                        graphics.setFont(font);
                        graphics.setColor(Color.BLUE);
                        super.paint(graphics);
                    }
                };
                LabelField somethingLabel = new LabelField("some Name",
                        USE_ALL_HEIGHT | USE_ALL_WIDTH) {
                    public void paint(Graphics graphics) {
                        graphics.setColor(Color.BROWN);
                        super.paint(graphics);
                    }
                };
                Font font = Font.getDefault().derive(Font.PLAIN, 6,
                        Ui.UNITS_pt);
                somethingLabel.setFont(font);
                fields[1] = somethingLabel;
            } else {
                fields[0] = new LabelField("  Shipping Date") {
                    public void paint(Graphics graphics) {
                        graphics.setColor(Color.BLUE);
                        super.paint(graphics);
                    }
                    protected void layout(int width, int height) {
                        // TODO Auto-generated method stub
                        int fontHeight = getFont().getHeight();
                        setExtent(width, fontHeight + 30);
                    }
                };
                LabelField dateLabel = new LabelField("some Date",
                        USE_ALL_HEIGHT | USE_ALL_WIDTH) {
                    public void paint(Graphics graphics) {
                        graphics.setColor(Color.BROWN);
                        super.paint(graphics);
                    }
                };
                Font myFont = Font.getDefault().derive(Font.BOLD, 9, Ui.UNITS_pt);
                dateLabel.setFont(myFont);
                fields[1] = dateLabel;
            }
            return fields;
        }
    };

    // Set up regions
    // dataTemplate.createRegion(new XYRect(0, 0, 1, 2), style);
    dataTemplate.createRegion(new XYRect(0, 0, 1, 1), style);
    dataTemplate.createRegion(new XYRect(1, 0, 1, 1), style);

    // Specify the size of each column by percentage, and the height of a
    // row
    dataTemplate.setColumnProperties(0, new TemplateColumnProperties(40,
            TemplateColumnProperties.PERCENTAGE_WIDTH));
    dataTemplate.setColumnProperties(1, new TemplateColumnProperties(60,
            TemplateColumnProperties.PERCENTAGE_WIDTH));

    dataTemplate.setRowProperties(0, new TemplateRowProperties(ROW_HEIGHT));

    // Apply the template to the view
    tableView.setDataTemplate(dataTemplate);
    dataTemplate.useFixedHeight(true);
    content1.add(tableView);

}

1 个答案:

答案 0 :(得分:1)

经过几天的测试后我注意到,我们无法在黑莓表视图中编辑标签的大小,我们只能编辑颜色和背景,但不能编辑大小或字体。