开发者

Linking drop down lists with files

开发者 https://www.devze.com 2023-03-18 01:04 出处:网络
How do I link the drop down lists with files in hard disk, so that on selecting an option in drop do开发者_C百科wn list (which is actually a folder in one of the drive of the hard disk) must get selec

How do I link the drop down lists with files in hard disk, so that on selecting an option in drop do开发者_C百科wn list (which is actually a folder in one of the drive of the hard disk) must get selected and it must display the files present in the folder in the same list?


I think what you need is a JFileChooser. You can find a tutorial on how to use it here.


You should get the directories you want to show (java.io.File instances) and use these directories as the items of the combo box. Then add an action listener of this combo box. This listener will be called each time the user selects one of the directories in the combo box. Then just ask the combo box its selected item, and list the files of the selected directory.

You may customize how the directories are displayed inside the combo box using a ListCellRenderer.

I suggest you read the Swing tutorial, where all this is well explained.

0

精彩评论

暂无评论...
验证码 换一张
取 消