Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I solved this problem by extending the <code>Field</code> class. Here is my version. Hope it helps.</p> <pre><code>/** * ColorButtonField is a custom button field that creates buttons of a specified * size and color. */ import net.rim.device.api.system.Display; import net.rim.device.api.ui.Color; import net.rim.device.api.ui.Field; import net.rim.device.api.ui.Font; import net.rim.device.api.ui.Graphics; import net.rim.device.api.ui.Keypad; public class ColorButtonField extends Field { private int backgroundColour; private int highlightColour; private int colour; private int fieldWidth; private int fieldHeight; private String text; private int padding = 8; private double fontWidth; private Font font; public ColorButtonField(String text, int highlightColour, int backgroundColour) { super(); this.text = text; this.highlightColour = highlightColour; this.backgroundColour = backgroundColour; colour = backgroundColour; font = Font.getDefault(); fieldHeight = font.getHeight() + padding; fontWidth = font.getHeight() / 2; fieldWidth = (Display.getWidth() - 12) / 3; this.setPadding(2, 2, 2, 2); } public ColorButtonField(String text, int highlightColour, int backgroundColour, int width, int height, int padding) { super(); this.text = text; this.highlightColour = highlightColour; this.backgroundColour = backgroundColour; colour = backgroundColour; font = Font.getDefault(); fieldHeight = height; fieldWidth = width; this.setPadding(2, padding, 2, padding); } public void setFont(Font font){ this.font = font; } public void setFocus(){ super.setFocus(); } public boolean isFocusable(){ return true; } protected boolean keyChar(char character, int status, int time) { if (character == Keypad.KEY_ENTER) { fieldChangeNotify(0); return true; } return super.keyChar(character, status, time); } protected boolean navigationClick(int status, int time) { fieldChangeNotify(0); return true; } protected void onFocus(int direction) { colour = highlightColour; invalidate(); } protected void onUnfocus() { colour = backgroundColour; invalidate(); } public int getPreferredWidth() { return fieldWidth; } public int getPreferredHeight() { return fieldHeight; } protected void layout(int arg0, int arg1) { setExtent(getPreferredWidth(), getPreferredHeight()); } protected void drawFocus(Graphics graphics, boolean on) { } protected void fieldChangeNotify(int context) { try { this.getChangeListener().fieldChanged(this, context); } catch (Exception e) {} } protected void paint(Graphics graphics) { graphics.setColor(colour); graphics.fillRoundRect(0, 0, fieldWidth, fieldHeight, 8, 8); graphics.setColor(colour + 0x333333); graphics.drawRoundRect(0, 0, fieldWidth, fieldHeight, 8, 8); graphics.setColor(Color.WHITE); if( 0 &lt; text.indexOf(' ')){ graphics.drawText(text.substring(0, text.indexOf(' ') ), fieldWidth / 2 - font.getAdvance(text.substring(0, text.indexOf(' ') )) / 2 , 5); graphics.drawText(text.substring(text.indexOf(' ') + 1), fieldWidth / 2 - font.getAdvance(text.substring(text.indexOf(' ') + 1)) / 2 , fieldHeight / 2); } else graphics.drawText(text, fieldWidth / 2 - font.getAdvance(text) / 2 , fieldHeight / 2 - 10); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload