【问题标题】:Increase label font in tableView blackberry增加tableView黑莓中的标签字体
【发布时间】:2014-04-16 08:52:49
【问题描述】:

我正在尝试增加插入到 tableView 中的标签中的字体,但以下代码都不起作用,就像我们只能影响标签的文本或背景颜色。

这就是我填充 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);

}

【问题讨论】:

    标签: blackberry font-size labelfield


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多