4 Replies - 839 Views - Last Post: 18 October 2012 - 11:10 AM Rate Topic: -----

#1 ceyesumma  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 31
  • Joined: 14-December 10

JFileChooser

Posted 04 October 2012 - 12:57 PM

Hello . I have a desktop app the via Jlist I attempt to open files I placed in
the windows file system. I can manipulate the JFileChooser Dialog enough to
dispaly the files in the dir that I wish to open. However,when I click open nothing
happens. I am running my app using Netbeans and have yet to jar the app and run it
alone. I noticed that in another application that is running without neatbeans that when I use The JfileChooser it displays a Windows window (FileChooser) and the files
can be opened normally. My application in Neatbeans displays a JfileChooser that
does not look like the windows system FileChooser.

How can I open my files with this JfileChooser running in Netbeans?
When I select the .txt file to open it does not open it . it will show the JFileChooser again. see output : thanks
I need to open NotePad.txt files and .doc files with word!
thanks



[output:]
CLASS
class FlashCardListSelectionHandler implements ListSelectionListener {:
--> in public FlashCardListSelectionHandler(javax.swing.event.ListSelectionEvent[ source=javax.swing.DefaultListSelectionModel 24600185 ={0} firstIndex= 0 lastIndex= 0 isAdjusting= false ]){ var:(ListSelectionEvent e)<--
: C:\Users\Steves\.targetFolders\admin_\admin\Note Folder\JFileChooser\open file\flashCard\openAFile.txt: systemDir:

--> in public void TargetFoldersAction.actionPerformed(flashCardChoiceBtn) var: (String actionCommand, String selectionName)<--

--> in private static File getDirectoryChoice( owner.getName() , C:\Users\Steves\.targetFolders\admin_\admin\Note Folder\JFileChooser\open file\flashCard\openAFile.txt , open file) var: (Component owner,String defaultDir,String title)<--

[/output]






 if (e.getActionCommand().equals("flashCardChoiceBtn")) {


            JInternalFrame frame = MusicSystemsJDesktopManager.getCurrentFrame();
            JTabbedPane pane = (JTabbedPane) frame.getContentPane().getComponent(0);
            int index = pane.getSelectedIndex();
            String tabName = pane.getTitleAt(index);

            Component comp = MusicSystemsJDesktopManager.getCurrentFrame();
            File fileSystemDir = OpenFlashCardListSelectionPanel.getChoiceDir();
            SwingUtil su = new SwingUtil();
            try {
                SwingUtil.getDirectoryChoice(comp, fileSystemDir, tabName);
            } catch (IOException ex) {
                Logger.getLogger(TargetFoldersAction.class.getName()).log(Level.SEVERE, null, ex);
            }
            view.MusicSystems.utilityFrame.doDefaultCloseAction();


        }






/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package view.utils;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Toolkit;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import javax.swing.JFileChooser;

/**
 *
 * @author Steves_
 */
public class SwingUtil {
    
    
  


    
    private static int rVal;
    private static File choice;
    public SwingUtil(){

    }
      public static File getDirectoryChoice(Component owner,String  defaultDir,String title){
        return getDirectoryChoice(owner,defaultDir,title);
    }
      
    public static File getDirectoryChoice(Component owner, File defaultDir, String title) throws IOException {


        String M = (" --> in private static File getDirectoryChoice( owner.getName()" + c + defaultDir + c + title + ") var: (Component owner,String defaultDir,String title)<-- \n");
        System.out.println(M);


        SecurityManager sm = null;
        JFileChooser jfc = null;
        choice = null;
        sm = System.getSecurityManager();
        System.setSecurityManager(null);

        jfc = new JFileChooser();
        jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        if((defaultDir!=null)&& defaultDir.exists()&& defaultDir.isDirectory()){

        }
        jfc.setCurrentDirectory(defaultDir);
            jfc.setSelectedFile(defaultDir);
        jfc.setDialogTitle(title);
       jfc.setApproveButtonText("OK");
        rVal = jfc.showOpenDialog(owner);
        jfc.requestFocus();
        switch (rVal) {
            case JFileChooser.APPROVE_OPTION:
                if (jfc.getSelectedFile() != null) {
                    if (jfc.getSelectedFile().exists()) {
                        choice = jfc.getSelectedFile();
                    } else {
                        File parentFile = new File(jfc.getSelectedFile().getParent());
                        choice = parentFile;
                        System.out.println(C + M + AND + choice.getName() + ":choice.getName() : \n");
                    }
                }
                break;

            case JFileChooser.CANCEL_OPTION:
            case JFileChooser.ERROR_OPTION:
        }
        jfc.removeAll();
        jfc = null;
        System.setSecurityManager(sm);


        return choice;
    }
     public static File getFileChoice(Component owner,String defaultSelection,FileFilter filter,String title){
         return SwingUtil.getFileChoice(owner, defaultSelection, filter, title);
     }
    public static File getFileChoice(Component owner,File defaultSelection,FileFilter filter,String title){

        
      System.out.println(M);

      SecurityManager sm=null;
      File choice=null;
      JFileChooser jfc = null;
      jfc= new JFileChooser();
      if(defaultSelection.isDirectory()){
          jfc.setCurrentDirectory(defaultSelection);
      }else{
          jfc.setSelectedFile(defaultSelection);
      }
      jfc.setFileFilter((javax.swing.filechooser.FileFilter) filter);
      jfc.setDialogTitle(title);
      jfc.setApproveButtonText("OK");
      int rVal=jfc.showOpenDialog(owner);

      owner.requestFocus();
      switch(rVal){
          case JFileChooser.APPROVE_OPTION:
              if(jfc.getSelectedFile()!=null){
                  choice=jfc.getSelectedFile();
              }
              break;
          case JFileChooser.CANCEL_OPTION:
          case JFileChooser.ERROR_OPTION:
      }
      jfc.removeAll();
      jfc=null;
      System.setSecurityManager(sm);


        return choice;
    }
public static Point getCenteringPoint(Dimension size){

    Point centeringPoint=new Point();
    Dimension screenSize;
    screenSize=Toolkit.getDefaultToolkit().getScreenSize();
    if(size.height>screenSize.width){
        size.width=screenSize.width;
    }
    centeringPoint.x=(screenSize.width=size.width)/2;
    centeringPoint.y=(screenSize.height-size.height)/2;
    
    return centeringPoint;
}
}





Is This A Good Question/Topic? 0
  • +

Replies To: JFileChooser

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10183
  • View blog
  • Posts: 37,596
  • Joined: 27-December 08

Re: JFileChooser

Posted 04 October 2012 - 01:14 PM

Please don't post help questions in the Advanced Discussion forum. Moved to Java.
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

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

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: JFileChooser

Posted 04 October 2012 - 07:25 PM

Stop mentionning Netbeans as a possible source of your problem and stop looking into it
Netbeans is just a fancy Java editor not really much
So you have problem with your Java code and you would habe the same problem using Netbeans or Notepad as editor
Was This Post Helpful? 0
  • +
  • -

#4 ceyesumma  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 31
  • Joined: 14-December 10

Re: JFileChooser

Posted 15 October 2012 - 11:00 AM

I have no idea about netbeans or note pad. You can use what ever you want. I was trying to find out how to get the
JFileChooser to open a file. I posted the code and I wanted to know how to fix it to open
a file.
Was This Post Helpful? 0
  • +
  • -

#5 ceyesumma  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 31
  • Joined: 14-December 10

Re: JFileChooser

Posted 18 October 2012 - 11:10 AM

START reading the post entirly and suppling some good code.

Someone actually did supply some related info to my question that I can share.
Your insert hyperlink does not work.

That's what the Class Desktopclass is for.
That's what the Class Desktop is for.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1