This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes browse button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "browse button" Watch "browse button" New topic
Author

browse button

Amit Yadav
Greenhorn

Joined: Aug 09, 2007
Posts: 8
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

Joined: Sep 11, 2006
Posts: 959

You can try to use JFileChooser.
http://java.sun.com/docs/books/tutorial/uiswing/components/filechooser.html


SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
What exactly do you want to browser?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Amit Yadav
Greenhorn

Joined: Aug 09, 2007
Posts: 8
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

Joined: Oct 27, 2005
Posts: 19651
    
  18

Create an action (or action listener) and attach it to the button.

Inside the actionPerformed method you can put something similar to this:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Roshan Khandelwal
Ranch Hand

Joined: Apr 16, 2009
Posts: 35
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

Joined: Oct 31, 2011
Posts: 498

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.


PM Me If You Want to get Urgent Help on Java Programming
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

I wouldn't put the label inside such a component. Only a few components include the label, such as JCheckBox and JRadioButton.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: browse button
 
Similar Threads
Non editable text box
How to add browse button to the applet
Renamae browse button of inputFile
code for the "add" button in file system
Browse Button Value