Question

I'm trying to increase font in a label inserted in tableView but nothing of the following code works, it's been like we can only affect the text or the background color of the Label.

This is how I fill my tableView, I used 4 different way for every Label but no one of them work!

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

}
Was it helpful?

Solution

What I noticed after days of testing that we can't edit the size of a label in a blackberry table view, we can only edit the color and background, but neither the size or the font.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top