java swing scroll can not work

修改

错误代码

    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)); 
posted @ 2019-06-17 20:13  JK-Z  阅读(103)  评论(0编辑  收藏  举报