JFileChooser help

I'm using NetBeans. I created a JFileChooser by selecting it in the Palette and then placed in on my GUI. I noticed that it created two buttons (Open and Cancel) and I would like to put in my code for those two button Action Events. I've looked at the source code but there is no place to put the code for it.
Does anyone know how to go about putting code for these two buttons?

RTFM
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JFileChooser.html#approveSelection()

Similar Messages

  • How to save a copy of a file to different location using jfilechooser

    hi, this is ravikiran,
    In my project there is a situation where when a user clicks on some button, a copy of a file(which is initially in my project folder) must be saved to a location specified by the user.
    I have no idea how to do this using JFileChooser.
    help me,
    thanx in advance

    JFileChooser lets you choose a file. Once it's done you will have to program the copy function with womething like :
         public void copyToDir(String fileSource,String fileDest) {
              try {
                   FileChannel srcChannel = new FileInputStream(fileSource).getChannel();
                   FileChannel dstChannel = new FileOutputStream(fileDest).getChannel();
                   dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
                   srcChannel.close();
                   dstChannel.force(true);
                   dstChannel.close();
              } catch (IOException e) {
                   e.printStackTrace();
         }

  • Help with "simple" JFileChooser problem...

    Hi all,
    how do I set the font in a JFileChooser???
    I have tried everything, but it always uses the Look & Feels default font setting. Can I change the default Look&Feels font setting?
    Greatfully for any suggestions!
    Cheers
    Anders ;-D

    Hello!
    You can use the UIManager, e.g. UIManager.put("FileChooser.font", new Font("Arial",
    Font.BOLD, 14);
    Well, that didn't seem to help with my case either. So I tried something else: I overrided all of the defaults by using UIManager.put(key, value) this way I got all of the Fonts in the JFileChooser to change.
    Correct me if I'm wrong... ;)
    - Cathra -
    Sample Code that performs the requested:
    // Prepare the resources
    FontUIResource font12Arial = new FontUIResource( "Arial", Font.PLAIN, 12 );
    // Put values into UIDefaults (before initializing the JFileChooser)
    UIManager.put( "ToolTip.font", font12Arial );
    UIManager.put( "OptionPane.messageFont", font12Arial );
    // shown for example
    UIManager.put("FileChooser.openButtonText", "OpenUp");
    UIManager.put("Button.font", font12Arial);
    UIManager.put("Label.font", font12Arial);
    UIManager.put("Table.font", font12Arial);
    UIManager.put("TextField.font", font12Arial);
    UIManager.put("ScrollPane.font", font12Arial);
    UIManager.put("ComboBox.font", font12Arial);
    UIManager.put("CheckBox.font", font12Arial);
    UIManager.put("TitledBorder.font", font12Arial);
    UIManager.put("RadioButton.font", font12Arial);
    UIManager.put("ToolTip.font", font12Arial);
    UIManager.put("TextPane.font", font12Arial);
    UIManager.put("TextArea.font", font12Arial);
    UIManager.put("Tree.font", font12Arial);
    UIManager.put("List.font", font12Arial);
    UIManager.put("MenuBar.font", font12Arial);
    UIManager.put("Menu.font", font12Arial);
    UIManager.put("MenuItem.font", font12Arial);
    UIManager.put("TableHeader.font", font12Arial);
    UIManager.put("TabbedPane.font", font12Arial);
    // somewhere in the code:
    JFileChooser c = new JFileChooser();
    c.showOpenDialog(aParentFrame);

  • JFileChooser weird problem (Help!!!)

    Does anyone here have loading problem with JFileChooser?
    I have a class that inherited the JFileChooser class and another class that inherited the JFrame class and this class create an instance of the JFileChooser class.
    My program sometime will not show (but sometime will: no changes at all) and they are no exception being shown on the console window what so ever. I can solve my program by initializing the JFileChooser object after showing the application and not before but that stupid JFileChooser is so slow to initialize. What the hell is going on? Any help hint would be appreciated.

    I also want to add that the following code is in my JFileChooser class:
    protected JDialog createDialog(Component Parent)
    JDialog CustomDialog=super.createDialog(Parent);
    CustomDialog.setLocationRelativeTo(Parent);
    CustomDialog.setResizable(false);
    return CustomDialog;
    Aside from the abnormally, I don't not what else could be causing the problem!

  • Missing pieces of components (JFileChooser, JButtons, etc) help?

    The normal window in the GUI i'm working on, works fine. When i bring up a new NetFrame (e.g. preferences) the components aren't drawn completely. None of the 3 buttons show up, a few check boxes in a tabbed pane show up (not all of them), etc. When i click where a button should be, it appears. When i switch to the other tab in the pane, its contents appear (except for a small missing bottom right corner of the border for a jtextarea), and when i switch back to the first tab, all of its contents appear. When i resize the panel, everything shows up.
    I've tried calling validate, revalidate, validateTree, repaint, show, pack, none of them do anything (pack rearranges things, but nothing new appears).
    I'm completely out of ideas!
    A previous version of the program works fine, so it is something wrong with my code (i.e. not my computer / packages etc).
    The thing that really stumps me, is that a JFileChooser appears incomplete -- only showing the file browser section, and the okay button (missing cancel button, and borders etc).
    I'm sorry i don't have any sample code to show, there too much to put it all, and i have no idea where the problem is.
    I'd appreciate any help or direction you have. THANKS!

    possibly related
    [http://forums.sun.com/thread.jspa?threadID=780103]

  • Need help for JFileChooser

    Hi,
    I need help on this one. I have a filechooser class which extended from JFileChooser class. Every thing works fine except this: I want to by hiting the "Enter" key to save the files. The "Enter" key works only when the focus is in the file name text field now, I want it to work when the focus is in the directory area, the file list area and the file type area as well. I try to add the KeyListener but how can I get hold of the component of the three areas of file chooser? I tried to add the KeyListener as Accessory, it didn't work either. Some one please help me.

    Try this to let your components react to ActionEvents
    comp.addActionListener(new  WhatIWantToDo());
    // WhatIWantToDo is the inner class.
    // Let it do what you want to be the reaction
    class WhatIWantToDo implements ActionListener {
    public void actionPerformed(ActionEvent event) {
    //  code on what you want to do
    }Or working without an inner class try this
    comp.addActionListener(new ActionListener() {
    // the event handling
    public void actionPerformed(ActionEvent event) {
    // your code for behavior
    // e.g. System.out.println("There is a reaction");
    // or specify a special named component as c1
    Object source = event.getSource();
    if (source == c1) doSomething();
    else if (source == c2) doOtherThings();
    });Hope this is of help for what you want. Else let me know.

  • Customizing JFileChooser (File Size) Need Help

    Can you help me with this. I want to customize my JFileChooser. I'm in a Windows environment so the file view that I see is same with that of the option pane of windows. What I would like to do is make the size that is viewed from the screen from ##KB to specific bytes size. (ex. 34421245). Can someone help me on this. I was able to see some codes on the net but those codes are not straightforward. They override the BasicFileChooserUI. Can someone help me on this. I don't want to override the BasicFileChooserUI instead I want to use the JFileChooser and change the size from ###KB to bytes. Thank you. ^_^

    Hi Rachel,
    My best idea for that is to load the swf files externally, so
    that each page is a different swf. A technique like this would be
    very simple and quick to use, because it only loads what you need
    when you need it.
    For example, you'd set the intro page to load right away, and
    then when you select "At Work" the intro page unloads and is
    replaced by the at work page.
    Another thing you may want to consider is holding the images
    in an xml file, and then using some basic flash/xml intergration to
    load each image as it's called. That way each image isn't stored in
    the flash file causing it to increase in size, and instead is
    actually loaded externally which is must faster.
    There are some great tutorials, if you're intrested, on how
    to do both of these at:
    http://www.kirupa.com/
    Hope I helped some!

  • JFilechooser .....help please

    hi,
    while opening file "OPEN" or "SAVE" dialog using JFilechooser, in those dialog, can we have our desired icon instead of Java Application at left most corner in the dialog??
    any help please????

    setIconImage
    public void setIconImage(Image image)Sets the image to be displayed in the minimized icon for this frame. Not all platforms support the concept of minimizing a window.
    Parameters:
    image - the icon image to be displayed. If this parameter is null then the icon image is set to the default image, which may vary with platform.
    See Also:
    getIconImage()
    That may work...

  • Small Help Needed in JFileChooser

    I've a small problem in using JFileChooser.
    I want to disable the doubleclick option if chosen is a file and enable if it is a folder
    or
    i want both the properties of singleclick and doubleclick to be same.
    i.e, if it is a folder as it gets inside the folder. incase of file it shudn't do anything (filechooser shudn't get closed). But as of now the file chooser is getting closed on double click on a file and it returns the selected file's name when i printed using chooser.getSelectedFile(). what i want now is, the filechooser shudn't return anything until i click the open button on the filechooser window.
    Can someone help me out in terlling me how to do this
    TIA

    um.... how about get the JDK?
    Also, please don't try to use a non-applet program as if it were an applet. It won't work.
    Also, please go through the Sun Java tutorials, especially the first ones about getting started.
    Edited by: Encephalopathic on Feb 26, 2008 9:56 PM

  • Help ! JCheckBox in JFileChooser ??

    hi..
    how will include a JCheckBox in A JFileChooser.showOpenDialog ?? my requirement is to create a Read only check Box in the showOpenDialog box .. is that possible.. if so please do help..
    Thanking you..
    rG.

    Quickest would be to sub JFileChooser.... :)
    It can also be added to a panel, so that is a possible solve as well...

  • Help abt JFileChooser

    can we change the back round color of JFileChooser to any other color..i mean the usual color is a dark one or so..so can v edit tht to some other color or can v put some kind of image on tht JFileChooser window..so tht the usual look 'll change..?pls help..

    JFileChooser respects Look And Feel settings doesn't it?
    So I suspect you'll have to create a custom look & feel... which I suspect (I've never done it) is a lot of work, for very little gain.
    Good luck with it.
    Keith.

  • Help me with my JFileChooser() please

    How can I set the directory to start inn, not use det default??

    Use the method setCurrentDirectory(File path) on your
    JFileChooser object.
    -- Alexis

  • JFileChooser....a small problem PLEASE HELP ME

    I have got a problem here. Here I have a JFileChooser, I want to add in
    a FileFilter, and user could only see some type of file. But as long as I
    try to get the extension....It wont compile, could any one teach me how
    to get the extension of a file in JFILECHOOSER???
    ============================================
    import java.io.*;
    import java.io.File.*;
    import javax.swing.filechooser.FileFilter;
    public class MainFrame extends JFrame implements ActionListener {
         public MainFrame() {.............}
         private boolean chooseFile()
              JFileChooser fileChooser = new JFileChooser();
              fileChooser.setFileSelectionMode( JFileChooser.FILES_ONLY );
              FileChoser filtering = new FileChoser("txt");
              fileChooser.setFileFilter(filtering);
              fileChooser.addChoosableFileFilter(filtering);
              int selection = fileChooser.showOpenDialog( this );
              if ( selection == JFileChooser.CANCEL_OPTION )
                   return false;     
              if (selection == -1) {
                   return false;
              File tmpfile = fileChooser.getSelectedFile();
              filename = tmpfile.toString();
              setTitle( "Smiggin Holes 2010 - " + filename );
              return true;
         static class FileChoser extends javax.swing.filechooser.FileFilter
              String extension;
              String description;
         public FileChoser(String extension, String description){
         this.extension = extension;
         this.extension = description;
         // Accept all directories and all gif, jpg, or tiff files.
         public boolean accept(File f)
              if (f != null)
              if (f.isDirectory())
              return true;
         String ext = getExtension(f); //<<<<<<<<<<<THE PROBLEM IS HERE WHEN I TRY TO GET THE EXTENSION OF THE FILE. IT CANT COMPILE
         System.out.println("aasdfasdf"+ext);
         if ((ext!=null)&&(ext.equals(extension)))
              return true;
    return false;
         // The description of this filter
    public String getDescription() {
         return "Just Text Files";
    ======================================
    Could you tell me what can I do? To get the extension of the file selected by the user?
    And What do I have to change?
    Regards,
    toStr

    First you write the following method
    public String getExtension( File f ) {
        if( f == null ) {
            return null ;
        String smallName = f.getName() ;
        int lastIndex = smallName.lastIndexOf( '.' ) ;
        if( lastIndex == -1 ) {
            return "" ;
        return smallName.substring( lastIndex ) ;
    }

  • Need help about JFileChooser

    how can I add a directory tree to the JFileChooser.
    such as the Windows's Explorer.
    the left panel is a directory tree and the right is a list of directory and file of the directory node selected.

    Now I'm using a file filter(filtering some kind of files and directories).
    I think that the problem is, after entering selected directory( for examples, "c:/temp" ) the dialog still says "temp".
    So, if i click "OPEN" button, i get "c:/temp" + "temp" ->
    "c:/temp/temp" i think.
    when entering directory, if user does not select a file(or directory) at all,
    the dirog says the name of entered dirctory?

  • I need a help about JFileChooser.

    First of all, as I'm not a native speaker, please understand my incorrect english.(^_^)
    I have a problem with JFileChooser.
    I use a JFileChooser to open file and Directory.
    ex) c:/temp/test1
    /test2
    /test3
    By using JFileChooser,
    1. Entere directory "temp" by double click
    2. Click "OPEN" button without select nothing.
    3. Then I was given the file named like "c:/temp/temp"
    What's the matter with me? And what should I be careful when using JFileChooser?

    Now I'm using a file filter(filtering some kind of files and directories).
    I think that the problem is, after entering selected directory( for examples, "c:/temp" ) the dialog still says "temp".
    So, if i click "OPEN" button, i get "c:/temp" + "temp" ->
    "c:/temp/temp" i think.
    when entering directory, if user does not select a file(or directory) at all,
    the dirog says the name of entered dirctory?

Maybe you are looking for

  • Install oracle 8.0.6 with Windows 2000

    hello all, today we have oracle 8.0.6 on NT Server ... we need install the same release oracle 8.0.6 on new IBM server, with Windows 2000 Server ... we are looking information about differences between config oracle 8.0.6 in NT Server and Windows 200

  • HT4848 can I create a cd or dvd for recovery disk?

    How i can create a dvd/cd recovery disk instead usb?

  • Help: simple request bean question

    Help! I have a request scoped bean GroupHandler which has a list of groups and I display them in a dataTable. Each row is a link to the "viewGroup.jsp" page which shows a detailed view of the selected group. Like so: <h:dataTable value="#groupHandler

  • IPad is sharing Safari over Bluetooth

    iPad mini, iPhone 5, iOS 8.3, both Verizon models AirDrop is off Shared AppleID Safari is disabled in iCloud settings It seems that when Bluetooth is on, my devices are sharing non-private Safari pages when they are active. For example, Safari is ope

  • Conversion of java Array to oracle SQL Array while calling Stored Procedure

    How java Array can be converted to oracle SQL array while calling Stored procedure with callable statement. i.e java Array ---> Sql Array in Oracle while setting the datatypes to callable statement arguments.