如何在Java中创建Listview?

jco*_*com 0 java user-interface swing jframe jlist

如何在Java中创建ListView?你能给我一个关于如何创建ListView的简单示例代码吗?

Eng*_*uad 14

你的意思是JList ?,请参阅java教程:如何使用列表


ada*_*ost 7

看看Java swing教程ListView API参考 - 它是<html>list 的实现- <ol><li>.

样品:

public class Sample extends JFrame   {
    public Sample(){
        JEditorPane pane = new JEditorPane();
        pane.setContentType("text/html");
        pane.setText("<ol id='foo'><li>One</li><li>Two</li></ol>"); 
        HTMLDocument doc = (HTMLDocument) pane.getDocument();
        add(pane);

        //Get the ref of foo element
        Element ele=doc.getElement("foo");
        ListView view=new ListView(ele);
        System.out.println(ele.getElementCount());
        try{
             doc.insertBeforeEnd(ele.getElement(0), "<ul><li>Test");          
        }catch(Exception ex){}
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(300,300);
        setVisible(true);
    }
}
Run Code Online (Sandbox Code Playgroud)