关于JScrollPane滚动面板的问题
各位大侠,我在创建JScrollPane滚动面板是遇见了这样两个问题:
第一个问题:
JTextArea ta=new JTextArea(20,15);
JScrollPane sp=new JScrollPane(ta); //这样写没有错误
JScrollPane sp=new JScrollPane(ta,1,0); //但这样写就抛出异常,能通过编译但就是不能运行。
或者将上句改为
JScrollPane sp=new JScrollPane(ta, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
import javax.swing.*;import java.awt.*;import java.awt.event.*;public class DemoScrollPane extends JFrame { DemoScrollPane() { super("ScrollPane"); Container cp=getContentPane(); cp.setLayout(new FlowLayout()); JTextArea ta=new JTextArea(20,15); JScrollPane sp=new JScrollPane(ta, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); cp.add(sp); setVisible(true); pack(); } public static void main(String sd[]){ DemoScrollPane frm=new DemoScrollPane(); }}JScrollPane sp=new JScrollPane(ta, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);