各位大侠,紧急请教
我现在用JList显示数据,把JList加入到JScrollPane中,发现纵向的滚动条是可以显示的,但是横向的怎么也显示不出来,不知道怎么回事?
看了别的贴,说是要设置面板的大小,但是我还是想知道有没有其他什么方法可以解决!
不胜感谢!
我现在用JList显示数据,把JList加入到JScrollPane中,发现纵向的滚动条是可以显示的,但是横向的怎么也显示不出来,不知道怎么回事?
看了别的贴,说是要设置面板的大小,但是我还是想知道有没有其他什么方法可以解决!
不胜感谢!
解决方案 »
- 求解??
- JScrollPane 滚动条无法滚动的问题
- java中有没有类似VB中shell功能的函数
- lucene搜索引擎的用法
- dwr3.0 Reverse Ajax 问题
- 初学者提问,这个错误是怎么回事?
- 【急】applet 传对象 到servlet 所遇到的问题
- 请教RandomAccessFile的用法
- class a里要引用class b里的方法,该方法为public,除了建类class b 的instance来引用该方法外还有什么办法引用???
- JBuilder6编辑器一有关键字后边就对不上,百分赠!
- "AWT-EventQueue-0" java.lang.NullPointerException 问题
- 初学者基础问题,我的ID就是立刻结贴的保障!
JScrollBar old = getHorizontalScrollBar();
this.horizontalScrollBar = horizontalScrollBar;
if (horizontalScrollBar != null) {
add(horizontalScrollBar, HORIZONTAL_SCROLLBAR);
}
else if (old != null) {
remove(old);
}
firePropertyChange("horizontalScrollBar", old, horizontalScrollBar); revalidate();
repaint();
}
或者设置 public void setHorizontalScrollBarPolicy(int policy) {
switch (policy) {
case HORIZONTAL_SCROLLBAR_AS_NEEDED://需要的时候偶偶显示
case HORIZONTAL_SCROLLBAR_NEVER://从不显示
case HORIZONTAL_SCROLLBAR_ALWAYS://总是显示
break;
default:
throw new IllegalArgumentException("invalid horizontalScrollBarPolicy");
}
int old = horizontalScrollBarPolicy;
horizontalScrollBarPolicy = policy;
firePropertyChange("horizontalScrollBarPolicy", old, policy);
revalidate();
repaint();
}
JList jList1 = new JList();
JScrollPane jScrollPane1=new JScrollPane(jList1,HORIZONTAL_SCROLLBAR_ALWAYS,VERTICAL_SCROLLBAR_ALWAYS );
....
jList1.setBackground(Color.lightGray);
jList1.setForeground(Color.BLACK);
jList1.setFixedCellHeight(15);
jList1.setFixedCellWidth(40);
........
panel1.add(jScrollPane1, new GridBagConstraints(0, 15, 2, 5, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 1, 0), 120, 62));
.........
Command="ROUTE:OPEN (@1:10,21:30)";
CommandList.add(Command);
jList1.setListData(CommandList);
.........
其中,就是在添加数据到jList1中,横向和纵向的滚动栏能够显示出来,但是横向的数据超过能显示的区域后,不能出现横向的滚动条的拖动项,即使加上了HORIZONTAL_SCROLLBAR_ALWAYS,也不行。
请高手指点迷经,不胜感谢!
private void jbInit() throws Exception {
vstrut1 = Box.createVerticalStrut(8);
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
jSeparator.setBackground(Color.darkGray);
jSeparator.setBorder(null);
jSeparator.setPreferredSize(new Dimension(1, 2));
jSeparator.setBounds(new Rectangle(27, 50, 628, 13));
setSize(new Dimension(813, 495));
setTitle("Frame Title");
jTabbedPane1.setBounds(new Rectangle(12, 18, 736, 397));
jLabel1.setText("请您选择需要导入财务数据的Excel文件:");
jLabel1.setBounds(new Rectangle(27, 20, 226, 15));
jPanel1.setLayout(null);
jButton1.setBounds(new Rectangle(574, 80, 81, 23));
jButton1.setText("选择文件");
jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
jScrollPane1.setHorizontalScrollBar(null);
jScrollPane1.setBorder(BorderFactory.createLineBorder(Color.black));
jScrollPane1.setToolTipText("");
jScrollPane1.setBounds(new Rectangle(27, 91, 501, 37));
jButton2.setBounds(new Rectangle(574, 132, 81, 23));
jButton2.setText("剔除文件");
jButton2.addActionListener(new Frame1_jButton2_actionAdapter(this));
jPanel1.setFont(new java.awt.Font("宋体", Font.PLAIN, 15));
jPanel1.setBorder(null);
contentPane.add(jTabbedPane1);
jPanel1.add(jScrollPane1);
jList1.setFixedCellHeight(20);
//jList1.setFixedCellWidth(80);
jScrollPane1.getViewport().add(jList1);
jPanel1.add(jSeparator);
jPanel1.add(jButton1);
jPanel1.add(jButton2);
jPanel1.add(jLabel1);
jScrollPane1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
jScrollPane1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); jTabbedPane1.add(jPanel2, "导入设置");
jTabbedPane1.add(jPanel1, "文件导入");