Do more! Do better!

java swing scroll can not work

Posted on By zjk

修改

错误代码

    JScrollPane scroll = new JScrollPane(jt);
    scroll.setViewportView(jt);            
    scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);  
    scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    jt.setPreferredSize(new Dimension(200,100));   

应将

jt.setPreferredSize(new Dimension(200,100));

改成

scroll.setPreferredSize(new Dimension(200,100));