4

How do I create in Java a GUI to allow a user to enter a directory into a text field and have a browse button next to it, so they can chose the folder easier? I need to do this using JComponents hopefully. Like the last entry shown here: http://www.adobe.com/support/dreamweaver/assets/flashbutton/images/ss5insertdialog.gif

mKorbel
  • 109,525
  • 20
  • 134
  • 319
anton2g
  • 923
  • 6
  • 12
  • 29
  • This [question](http://stackoverflow.com/questions/7195495/file-browser-component-for-java-swing) will be useful to you. – ring bearer Oct 03 '11 at 18:55

2 Answers2

3

Use a JTextField and JFileChooser You have a demo here : http://download.oracle.com/javase/tutorial/uiswing/components/filechooser.html

http://www.exampledepot.com/egs/javax.swing.filechooser/CreateDlg.html

Cris
  • 4,947
  • 6
  • 44
  • 73
2

You need to trigger a JFileChooser with the button, and then listen to its response to populate the field. Tutorial here. If you don't want people to manually edit the field, set it disabled so that it can't be edited, but does show the text.

Sajid
  • 4,381
  • 20
  • 14