简体   繁体   English

JList-添加滚动按钮

[英]JList - add scroll button

I have JList code that I want to add to a scroll button on the side since the list is longer than the text box window. 我有要添加到侧面滚动按钮的JList代码,因为列表比文本框窗口长。 that's the code: 那是代码:

final JList list = new JList();
        list.setBounds(36, 23, 366, 241);
        contentPane.add(list);
File folder = new File(FILETOSTART);
                        File[] listOfFiles = folder.listFiles();

                        for (int i = 0; i < listOfFiles.length; i++) {
                            if (listOfFiles[i].isFile()) {
                                System.out.println("File " + listOfFiles[i].getName());
                                list.setListData(listOfFiles);                              
                            } else if (listOfFiles[i].isDirectory()) {
                                System.out.println("Directory " + listOfFiles[i].getName());
                            }
                        }
                    }
                    in.close();
                }
                catch (Exception exception) {
                    exception.printStackTrace();

How can I add this scroll side button? 如何添加此滚动侧按钮?

If by 'button' you mean 'scroll bar' then it can be 1 as simple as: 如果用“按钮”表示“滚动条”,则它可以是1 ,简单如下:

contentPane.add(new JScrollPane(list));

Instead of: 代替:

contentPane.add(list);
  1. Except when using absolute positioning, as seems might be the case here. 除了使用绝对定位时,在这里似乎是这种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM