java - 如何在诺基亚asha sdk1.0中使textArea可滚动

标签 java java-me nokia s40

我正在开发诺基亚asha sdk1.0。我在我的应用程序中使用TextArea,但我的textarea不可滚动。我使用了以下代码,那么如何使其可滚动。

Display.init(this);
        Display.getInstance().setForceFullScreen(true);
        Form form=new Form();
        form.setScrollable(false);
        form.getUnselectedStyle().setBgColor(10175989);
        form.setLayout(new BorderLayout());
        Container northcon=new Container();
        int northcomponentHT=form.getPreferredH()*20/100;
        northcon.setPreferredH(northcomponentHT);
        Label northlab=new Label("NORTH");
        northcon.addComponent(northlab);
        form.addComponent(BorderLayout.NORTH,northcon);
        Container centercon=new Container();
        TextArea textarea=new TextArea();
        int centercomponentHT=form.getPreferredH()*60/100;
        textarea.setPreferredH(centercomponentHT);
        textarea.setPreferredW(form.getPreferredW());
        String string=new String("dfjjkfjknfsdfhkfjfjcannot be surpassed by that of watching electric lights. Everyone in Gods creation is special and so are wcannot be surpassed by that of watching electric lights. Everyone in Gods creation is special and so are wcannot be surpassed by that of watching electric lights. Everyone in Gods creation is special and so are wcannot be surpassed by that of watching electric lights. Everyone in Gods creation is special and so are wcannot be surpassed by that of watching electric lights. Everyone in Gods creation is special and so are wcannot be surpassed by that of watching electric lights. Everyone in Gods creation is special and so are wcannot be surpassed by that of watching electric lights. Everyone in Gods creation is special and so are wkfiufjkfjkfjfjkfjierojfkjjiojkldf;jasf;ljsf;jl;dfjas;dflk;lfj;asdfljsdl;fkjierojeiorjoiejkfjoeirjjeoirjoejo;efdfkljoijerjorj");
        textarea.setScrollVisible(true);

        textarea.setText(string);
        textarea.setEditable(false);
        textarea.setGrowByContent(true);
        textarea.setRows(50);

        //centercon.setScrollable(true);
        centercon.addComponent(textarea);

        form.addComponent(BorderLayout.CENTER,centercon);
        Container southcon=new Container();
        int southcomponentHT=form.getPreferredH()*20/100;
        southcon.setPreferredH(southcomponentHT);
        Label southlab=new Label("SOUTH");
        southcon.addComponent(southlab);
        form.addComponent(BorderLayout.SOUTH,southcon);
        form.show();

最佳答案

要使 TextArea 文本可滚动,您必须使用滚动 Pane 。

你需要做类似的事情

JScrollPane scrollPane = new JScrollPane(textarea);

有关 JScrollPanes 的更多信息,请访问 http://docs.oracle.com/javase/7/docs/api/javax/swing/JScrollPane.html

关于java - 如何在诺基亚asha sdk1.0中使textArea可滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19581028/

相关文章:

geocoding - 我可以使用 NOKIA\Here API (REST) 获取地理位置(纬度\经度)并将地址信息作为输入

qt - 如何在Qt中获取selectionchange事件

java - 从数据库读取时出现"Invalid cursor state"错误

java - 在黑莓中创建类似于邮件应用程序的分组 TableView

http - 使用 J2ME 上传一个 wav 文件

c++ - 将数组值绑定(bind)到诺基亚 Qt 中的 ListView 控件?

java - 从 MP3 文件中获取解码后的字节流

Java - 将 String[] 数组的所有值转换/复制到 ArrayList<BigInteger>

java - 创建基于模块/包的项目?

java - 将 j2me Polish 与 Netbeans 一起使用时出现问题