Search code examples
javablackberrylabelfield

BlackBerry vertically center LabelField with custom height


I have a LabelField nested within a TableLayoutManager row. I want the row to be a specific height (the same height as its bitmap background). In order to achieve this, I changed the layout() method of the nested LabelField:

LabelField lblHours = new LabelField(hours,
            Color.BLACK, Manager.FIELD_VCENTER) {
        protected void layout(int width, int height) {
            super.layout(width, 40 //height of the bitmap);
            setExtent(width, 40 //height of the bitmap);
        }
    };

This successfully increased the TableLayoutManager row size. However, once I do this, the LabelField is no longer centered vertically within the row. Any suggestions on how to do that?

Thanks!


Solution

  • The above answer works just make sure that you put in two statements for the above.. as illustrated in the below example.

    LabelField importanceLabel = new LabelField("Importance: ",LabelField.FIELD_VCENTER | LabelField.FIELD_RIGHT) {
              public void paint(Graphics g) { 
                  g.setColor(0x145085); 
                  super.paint(g); 
              } 
              protected void layout(int width, int height) {
                  super.layout(Math.min(width, this.getFont().getAdvance(this.getText())), 26); //height of the bitmap);
                  setExtent(Math.min(width, this.getFont().getAdvance(this.getText())), 26); //height of the bitmap);
              }
          };
    

    This is going to be the same response.. and thank you guys.. for the discussion. It helped me.