现有一个panel,我在里面套了 Box verticalscanDocDrPane = Box.createVerticalBox();然后还有若干个   Box horizontalscanDocDrPane = Box.createVerticalBox();套在verticalscanDocDrPane 这个里面也就是verticalscanDocDrPane.add(horizontalscanDocDrPane);
      panel.add(verticalscanDocDrPane);然后因为行数太多了,所以需要加滚动条,但是好像直接把这个panel加到 JScrollPane里面不行

解决方案 »

  1.   

     JScrollPane jp=new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    jp.setViewportView(verticalscanDocDrPane);
    verticalscanDocDrPane.setPreferredSize(new Dimension(360,512));
    verticalscanDocDrPane.revalidate();出现了滚动条,但是滚动条好像不能拖动
      

  2.   

    JScrollPane jp=new JScrollPane();
    就直接构造个add进去就行了。平常都能拖动的呀。
      

  3.   


    thumbnailPane = new JPanel();   
        JLabel lt;
    Box testPane = Box.createVerticalBox();
    for(int i = 0;i < 100;i++){
        lt = new JLabel("备注"+i,10); 
        testPane.add(lt);
     }   
      thumbnailPane.add(testPane);
      thumbnailPane.setPreferredSize(new Dimension(170,510));
      thumbnailPane.setBackground(Color.WHITE);
       JScrollPane jp=new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                         ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
       jp.setViewportView(thumbnailPane);
       thumbnailPane.setPreferredSize(new Dimension(170,510));
       thumbnailPane.revalidate();
       horizontalScandocDRPane.add(jp);结果显示到备注28,下面的都没显示也不能拖动
      

  4.   

    这里API和源码例子
    一个英文的,一个翻译的:
    http://apicode.gicp.net/class.do?api=selectByfatherIndex&father=255
    http://apicodecn.gicp.net/class.do?api=selectByfatherIndex&father=255
      

  5.   

     
    thumbnailPane = new JPanel(new GridLayout(100,1));
     for(int i=0;i<100;i++){
    JTextField jlb = new JTextField("tong"+i,10);
    thumbnailPane.add(jlb);
    }
    scrollPane = new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); 
      scrollPane.setViewportView(thumbnailPane);
      thumbnailPane.setPreferredSize(new Dimension(180,2000));
      thumbnailPane.revalidate();
      horizontalScandocDRPane.add(scrollPane);结果发现只显示到tong26,而且横向的滚动条和剩下的文本框都没能显示出来,感觉纵向的也只是形同虚设,无法拖动,快崩溃了,各位大大就我啊~~~~~
      

  6.   


    thumbnailPane = new JPanel(new GridLayout(100, 1));
    for (int i = 0; i < 100; i++) {
    JLabel jlb = new JLabel("tong" + i);
    thumbnailPane.add(jlb);
    }
    scrollPane = new JScrollPane(
    ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    scrollPane.setViewportView(thumbnailPane);
    thumbnailPane.setPreferredSize(new Dimension(180, 2000));
    thumbnailPane.revalidate();
    // horizontalScandocDRPane.add(scrollPane);
    this.add(scrollPane);不注释上面代码所注释的那行,会报空指针异常。(就是上面所注释的那行)注释之后就不会报错。而且出现滚动条了,也可以拖动。