50% OFF!!!

Tuesday, June 22, 2010

lwuit | j2me link control (component)

Here is an implemantation of a LINK component for the LWUIT enviroment under J2ME (Java ME).
This code creates a lwuit link component based on the lwuit button which not have a border and is transparent! also have an appropriate color (blue) and font style (underline).
hope it is helpful:

code example:

Button btn = new Button("LINK1");
//btn.getStyle().setBorder(Border.createEmpty());
btn.getUnselectedStyle().setBorder(Border.createEmpty());
btn.getSelectedStyle().setBorder(Border.createEmpty());

//btn.getStyle().setBgTransparency(100);
btn.getUnselectedStyle().setBgTransparency(100);
btn.getSelectedStyle().setBgTransparency(100);

//btn.getStyle().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_UNDERLINED, Font.SIZE_MEDIUM));
btn.getUnselectedStyle().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_UNDERLINED, Font.SIZE_MEDIUM));
btn.getSelectedStyle().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_UNDERLINED | Font.STYLE_BOLD, Font.SIZE_MEDIUM));

//btn.getStyle().setFgColor(0x0000ff);
btn.getUnselectedStyle().setFgColor(0x0000ff);
btn.getSelectedStyle().setFgColor(0x0000ff);



Enjoy!

4 comments:

  1. You can upgrade your code and create an object (class) looking like:


    public class LinkButton extends Button
    {
    public LinkButton()
    {
    this.getUnselectedStyle().setBorder(Border.createEmpty());
    this.getSelectedStyle().setBorder(Border.createEmpty());

    this.getUnselectedStyle().setBgTransparency(100);
    this.getSelectedStyle().setBgTransparency(100);

    this.getUnselectedStyle().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_UNDERLINED, Font.SIZE_MEDIUM));
    this.getSelectedStyle().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_UNDERLINED | Font.STYLE_BOLD, Font.SIZE_MEDIUM));

    this.getUnselectedStyle().setFgColor(0x0000ff);
    this.getSelectedStyle().setFgColor(0x0000ff);
    }
    }


    i noticed that you also need to handle the PRESSED style by: this.getPressedStyle() for handling color/font/border and additionally set the padding & marging to (0,0,0,0)


    j.l

    ReplyDelete
  2. here is my style code:

    // border
    btn.getStyle().setBorder(Border.createEmpty());
    btn.getUnselectedStyle().setBorder(Border.createEmpty());
    btn.getSelectedStyle().setBorder(Border.createEmpty());

    // transparent
    btn.getStyle().setBgTransparency(100);
    btn.getUnselectedStyle().setBgTransparency(100);
    btn.getSelectedStyle().setBgTransparency(100);

    // margin & padding
    btn.getStyle().setMargin(0, 0, 0, 0);
    btn.getSelectedStyle().setMargin(0, 0, 0, 0);
    btn.getUnselectedStyle().setMargin(0, 0, 0, 0);
    btn.getPressedStyle().setMargin(0, 0, 0, 0);
    btn.getStyle().setPadding(0, 0, 0, 0);
    btn.getSelectedStyle().setPadding(0, 0, 0, 0);
    btn.getUnselectedStyle().setPadding(0, 0, 0, 0);
    btn.getPressedStyle().setPadding(0, 0, 0, 0);


    j.l

    ReplyDelete
  3. hi, i want to give an action for the button could you please help

    ReplyDelete
  4. Thanks for sharing this huge info with us.

    ReplyDelete