也就是verticalscanDocDrPane.add(horizontalscanDocDrPane);
panel.add(verticalscanDocDrPane);
然后因为行数太多了,所以需要加滚动条,但是好像直接把这个panel加到 JScrollPane里面不行
11 个解决方案
#1
JScrollPane jp=new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
jp.setViewportView(verticalscanDocDrPane);
verticalscanDocDrPane.setPreferredSize(new Dimension(360,512));
verticalscanDocDrPane.revalidate();
出现了滚动条,但是滚动条好像不能拖动
jp.setViewportView(verticalscanDocDrPane);
verticalscanDocDrPane.setPreferredSize(new Dimension(360,512));
verticalscanDocDrPane.revalidate();
出现了滚动条,但是滚动条好像不能拖动
#2
没人回答的?
#3
JScrollPane jp=new JScrollPane();
就直接构造个add进去就行了。平常都能拖动的呀。
就直接构造个add进去就行了。平常都能拖动的呀。
#4
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,下面的都没显示也不能拖动
#5
#6
是不行的。。。我也遇到过。。
#7
那您怎么处理的呢?
#8
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,而且横向的滚动条和剩下的文本框都没能显示出来,感觉纵向的也只是形同虚设,无法拖动,快崩溃了,各位大大就我啊~~~~~
#9
scrollPane.setPreferredSize试试看
#10
楼上正解
#11
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);
不注释上面代码所注释的那行,会报空指针异常。(就是上面所注释的那行)注释之后就不会报错。而且出现滚动条了,也可以拖动。
#1
JScrollPane jp=new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
jp.setViewportView(verticalscanDocDrPane);
verticalscanDocDrPane.setPreferredSize(new Dimension(360,512));
verticalscanDocDrPane.revalidate();
出现了滚动条,但是滚动条好像不能拖动
jp.setViewportView(verticalscanDocDrPane);
verticalscanDocDrPane.setPreferredSize(new Dimension(360,512));
verticalscanDocDrPane.revalidate();
出现了滚动条,但是滚动条好像不能拖动
#2
没人回答的?
#3
JScrollPane jp=new JScrollPane();
就直接构造个add进去就行了。平常都能拖动的呀。
就直接构造个add进去就行了。平常都能拖动的呀。
#4
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,下面的都没显示也不能拖动
#5
这里API和源码例子
一个英文的,一个翻译的:
http://apicode.gicp.net/class.do?api=selectByfatherIndex&father=255
http://apicodecn.gicp.net/class.do?api=selectByfatherIndex&father=255
一个英文的,一个翻译的:
http://apicode.gicp.net/class.do?api=selectByfatherIndex&father=255
http://apicodecn.gicp.net/class.do?api=selectByfatherIndex&father=255
#6
是不行的。。。我也遇到过。。
#7
那您怎么处理的呢?
#8
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,而且横向的滚动条和剩下的文本框都没能显示出来,感觉纵向的也只是形同虚设,无法拖动,快崩溃了,各位大大就我啊~~~~~
#9
scrollPane.setPreferredSize试试看
#10
楼上正解
#11
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);
不注释上面代码所注释的那行,会报空指针异常。(就是上面所注释的那行)注释之后就不会报错。而且出现滚动条了,也可以拖动。