• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

browse button

 
Amit Yadav
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am designing a page layout in swing and i want to make a browse button on that page.so please help me, how can i create a browse button.please give me source code for that.
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try to use JFileChooser.
http://java.sun.com/docs/books/tutorial/uiswing/components/filechooser.html
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly do you want to browser?
 
Amit Yadav
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actully sir i want a browse button which browse a file in a textfield. JFileChooser create a window,but i want it will handeled in a textfield.
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create an action (or action listener) and attach it to the button.

Inside the actionPerformed method you can put something similar to this:
 
Roshan Khandelwal
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob... It was of real help. I was actually stuck and the example provided really helped.
Thanks
and Thanks Amit for having asked this question .
 
Nam Ha Minh
Ranch Hand
Posts: 504
Eclipse IDE Firefox Browser Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think we should create a reusable component for that, such as File picker component in Swing

That would save us time to rewrite JFileChooser related stuffs like label, text and button which are standard widgets for a file browser component.
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't put the label inside such a component. Only a few components include the label, such as JCheckBox and JRadioButton.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic