1

*I am developing one j2me-Lwuit Project for Nokia s40 devices.I have some problem abuot ticker. I have apply Only one color for tiker.But i want differnt color to apply for single ticker.This is my code for Ticker:

       Ticker tick;
        String tickerText=" ";
         Label lblIndice=new Label();
    Label ticker=new Label("");
    for (int i = 0; i < tickerIndiceData.size(); i++) 
        {
            tickerText +=" "+tickerIndiceData.elementAt(i).toString();
            tickerText +=" "+tickerValueData.elementAt(i).toString();
            tickerText +=" "+"("+tickerChangeData.elementAt(i).toString()+")";
            lblIndice.setText(" "+tickerIndiceData.elementAt(i).toString());
            lblValue.setText(" "+tickerValueData.elementAt(i).toString());
            double val=Double.parseDouble(tickerChangeData.elementAt(i).toString());
            if(val>0)
            {
                ticker.getStyle().setFgColor(0X2E9F37);
            }
            else
            {
                ticker.getStyle().setFgColor(0XFF0000);
            }
            lblChange.setText(" "+"("+val+")");
        }
        System.out.println("TICKER==="+tickerText);
ticker.setText(tickerText);
        ticker.getStyle().setFont(Font.createSystemFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD, Font.SIZE_SMALL));
        ticker.startTicker(50, true);*
Gorkem Ercan
  • 3,220
  • 1
  • 18
  • 26
ranjith
  • 99
  • 7

1 Answers1

1

LWUIT doesn't support different colors for a label (hence ticker) since that would require quite a bit of processing.

Implementing a ticker from scratch in LWUIT is pretty easy though. Just derive label and override paint as such:

public void paint(Graphics g) {
    UIManager.getInstance().setFG(g, this);
    Style style = l.getStyle();
    Font f = style.getFont();
    boolean isTickerRunning = l.isTickerRunning();
    int txtW = f.stringWidth(text);

    // update this to draw two strings one with the color that's already set and the
    // other with the color you want
    g.drawString(getText(), getShiftText() + getX(), getY(),style.getTextDecoration());        
}
Shai Almog
  • 51,749
  • 5
  • 35
  • 65