Question

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!

Was it helpful?

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.

OTHER TIPS

Try changing setExtent(width, 40) to setExtent(this.getWidth(), 40). This could possibly not work if getWidth() is trying to take up all of the available width (which is what your setExtent() call is doing), and since the text will be drawn left-aligned, it looks like your field isn't centered but in reality it's just taking up the entire cell of your table. Alternatively, if this doesn't work you may be able to do setExtent(Math.min(width, this.getFont().getAdvance(this.getText())), 40);

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