5 Replies - 1372 Views - Last Post: 18 July 2011 - 11:30 PM Rate Topic: -----

#1 newaudrey  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 162
  • Joined: 08-July 10

JFilechooser problem please help me.

Posted 18 July 2011 - 12:46 AM

i have problem on my JFilechooser..
Please help me. sir, ma'am, friends
# 1. how to filter the files using JFIlechooser what i want to show is the pictures like .jpg format
# 2. another question is there something wrong with my code? what i mean is if there are a better way to do this

this is my code in my browse button
JFileChooser fc = new JFileChooser();
        fc.showOpenDialog(null);
        jTextField1.setText(fc.getSelectedFile().getName());
        String tmp = fc.getSelectedFile().getPath();
        jButton1.setIcon(new ImageIcon(tmp));


sorry for my bad english

This post has been edited by newaudrey: 18 July 2011 - 12:47 AM


Is This A Good Question/Topic? 0
  • +

Replies To: JFilechooser problem please help me.

#2 masijade  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 196
  • View blog
  • Posts: 580
  • Joined: 03-April 10

Re: JFilechooser problem please help me.

Posted 18 July 2011 - 01:01 AM

See the swing tutorials for JFileChooser and the FileNameFilter interface.
Was This Post Helpful? -1
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: JFilechooser problem please help me.

Posted 18 July 2011 - 09:08 PM

 JFileChooser chooser = new JFileChooser();
 FileNameExtensionFilter filter = new FileNameExtensionFilter(
        "JPG & GIF Images", "jpg", "gif");
  chooser.setFileFilter(filter);


Was This Post Helpful? 0
  • +
  • -

#4 newaudrey  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 162
  • Joined: 08-July 10

Re: JFilechooser problem please help me.

Posted 18 July 2011 - 10:38 PM

sir pbl i receive an error
cannot find symbol: FileNameExtensionFilter
Was This Post Helpful? -1
  • +
  • -

#5 jokham  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 54
  • Joined: 08-May 10

Re: JFilechooser problem please help me.

Posted 18 July 2011 - 11:19 PM

Did you import the class?
import javax.swing.filechooser.FileNameExtensionFilter;

Was This Post Helpful? 1
  • +
  • -

#6 masijade  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 196
  • View blog
  • Posts: 580
  • Joined: 03-April 10

Re: JFilechooser problem please help me.

Posted 18 July 2011 - 11:30 PM

View Postnewaudrey, on 19 July 2011 - 07:38 AM, said:

sir pbl i receive an error
cannot find symbol: FileNameExtensionFilter


So, it seems that someone is adverse to a little reading and needs cut-n-paste that needs no further thought. You do not learn anything this way, and you definately do not learn anything if you're not even willing to try to correct anything in the cut-n-paste spoonfeeding that you are given.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1