首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 其他相关 >

Lwuit-小细节疑难杂症收拾

2012-11-06 
Lwuit---小细节疑难杂症整理1、textArea 显示文本内容,在部分手机上无法显示全部内容,每一行的最后几个字被

Lwuit---小细节疑难杂症整理
1、textArea 显示文本内容,在部分手机上无法显示全部内容,每一行的最后几个字被挡住
琢磨了很久终于找了出来,解决方案如下:
  TextArea txtContent = new TextArea(strContent, 12, 24);
  //添加这一句即可
  txtContent.setWidestChar('一');

2、若要对文本框中的内容设置补丁:
txtContent.getStyle().setPadding(Component.RIGHT, 10);
内容往右10像素。

3、如果list上不想要显示文字多余时的省略号
  name.setEndsWith3Points(false);

4、重写Dialog要让标题与Form的样式一致
dialog.show(100, 100,100,100, true);

5、声音播放
try {
     InputStream is = getClass().getResourceAsStream(
       "/res/NewMailSound.wav");
     Player player = Manager.createPlayer(is, "audio/x-wav");
     player.start();
    } catch (Exception e) {
     e.printStackTrace();
    }

6、使得TextField也能够在触屏手机上点击时出现输入编辑
解决方法:
在TextField源码上 加上editString();函数:
public void pointerReleased(int x, int y) {
        // unlike text area the text field supports shifting the cursor with the touch screen
     editString();
        String text = getText();
        int textLength = text.length();
        int position = 0;
        Font f = getStyle().getFont();
        x -= getAbsoluteX();
        for(int iter = 0 ; iter < textLength ; iter++) {
            int width = f.substringWidth(text, 0, iter);
            if(x > width) {
                position = iter;
            } else {
                break;
            }
        }
        if(position == textLength - 1) {
            if(f.stringWidth(text) < x) {
                position = textLength;
            }
        }
        setCursorPosition(position);
        repaint();
    }

或者官方的解决方法:http://forums.java.net/jive/thread.jspa?threadID=52716

7、震动
public void MakeVibrate() {
  new Thread() {
   public void run() {
    try {
     Display.getInstance().vibrate(2000);
    } catch (Exception e) {
     e.printStackTrace();
    }
   }
  }.start();
}


8、导致内存激增的原因(可以用自动模拟器的内存检测器进行监测C:\WTK2.5.2\bin\prefs.exe将你要的设置勾选)
而lwuit里面的源码有两句是会导致内存一直占用,一个是TextField中的这段代码


17、NokiaS60手机出现string index异常的原因。

com.sun.lwuit.Font.charWidth(char)

1、TextArea  line:186

   private static char widestChar = '国';

2、HTMLTextArea  line:33

   private static char widestChar = '一';

3、DefaultLookAndFeel  line:1124

   int widest = f.charWidth('国');

热点排行