1

*我正在为诺基亚 s40 设备开发一个 j2me-Lwuit 项目。我有一些关于股票代码的问题。我只为tiker应用了一种颜色。但我想要不同的颜色来应用单个ticker。这是我的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);*
4

1 回答 1

1

LWUIT 不支持标签的不同颜色(因此代码),因为这需要相当多的处理。

不过,在 LWUIT 中从头开始实现代码非常容易。只需像这样导出标签并覆盖油漆:

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());        
}
于 2011-09-11T06:15:23.737 回答