JFileChooser.showSaveDialog ()

I have to save a file using
JFileChooser fc=new JFileChooser()
//a dded all the filters
fc.showSaveDialog();
If we write a file name in the file name text box of chooser and pressed SAVE button,
Its saving with the selected file name.
But I have to ask a question " THE FILE ALREADY EXISTS DO U WANT TO REPLACE"
If the user presses "yes" option only the file chooser shloud close.
If the user pressed "no" option the file chooser should not close,that allows user for another file name.
how can I do it,
waiting,
thanks,

You have six questions of the most recent 20 questions asked on this forum. It would appear you should spend some time reading tutorials before starting a new project. The [url http://java.sun.com/docs/books/tutorial/uiswing/TOC.html]Swing Tutorial and the Java API are good places to start for basic information.

Similar Messages

  • JFileChooser.showSaveDialog() to be displayed along with calling screen

    hi,
    i have a frame ,in that i placed many components,one of the component is Jbutton,when the user click on this button ,it calls JFileChooser.showSaveDialog() to save a file in local system.
    After opening "file save window" , without clicking file save button ,if i open some other application(like WSAD,textpad) i am not able to see "file save window" until unless i search for that window by using "alt+tab".
    here what i am trying to say is "file save window " always needs to be on top of its calling screen.
    i even used JFileChooser .showSaveDialog(Component parent) ,but still that is not happening,if anyone come across this problem ,please help me.
    thanks in advance..

    hi PhHein,
    perfect answer.
    Thanks for your reply,your answer made me think on my code .There was small issue in my code and its been resolved now.

  • JFileChooser.showSaveDialog and Filename field

    I am implementing the actionPerformed method for a "Save As" menu command. In my standard JFileChooser "Save" dialog (showSaveDialog, Metal L&F), I volunteer the current filename (by a previous call to setSelectedFile). The dialog opens just fine. If the user selects a file in the list, the name of the selected file appears in the "File name" textfield as expected. But if the user selects a directory in the list, the name of the directory likewise appears in the "File name" textfield.
    From other programs (including JBuilder4) I am used to having the filename stay put when I select and/or open a directory in a Save Dialog. Is this just the way a JFileChooser save dialog works in the Metal L&F, am I doing something strange, or is there a workaround?
    Thanks very much.
        File tempFile = new File( activePI.getPathname() );
        defaultSaveDir = tempFile.getParentFile();
        JFileChooser chooser = new JFileChooser(defaultSaveDir);
        chooser.setSelectedFile(tempFile);

    Thanks to both of you for the help. I actually came up with the key element of trevorryan1's solution shortly after posting my followup yesterday: consuming any setSelectedFile call when the file argument is a directory. Once this test is in, the counter etc is no longer needed! I consider the JFileChooser's "overwrite the filename textfield" behavior to be a bug, since my !file.isDirectory() override of setSelectedFile shouldn't do anything that setFileSelectionMode(JFileChooser.FILES_ONLY) doesn't already do (FILES_ONLY is the default setting).
    Here is the test class that I posted to the BugParade; I'll post the URL when/if it shows up.
    import java.io.File;
    import javax.swing.JFileChooser;
    class JFileChooserBug
      //Note: comment out the first or second declaration of JFileChooser chooser
      public static void main(String[] args)
        // 1. in a standard JFileChooser save dialog, navigating to another
        // directory will (inappropriately) overwrite the "File name:" textfield.
        // This should not happen when fileSelectionMode = FILES_ONLY (the default).
        JFileChooser chooser = new JFileChooser();
        // 2. in a JFileChooser with a hacked setSelectedFile method, the
        // "File name:" text field is (appropriately) left alone.
        //JFileChooser chooser = new MyJFileChooser();
        //chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);  // = default anyway
        // show the Save dialog with a default file selected
        chooser.setSelectedFile( new File("dummyfile") );
        chooser.showSaveDialog(null);
      public static class MyJFileChooser extends JFileChooser
        //OVERRIDE
        public void setSelectedFile(File file)
          if ( !file.isDirectory() )
            super.setSelectedFile(file);
    }

  • NullPointerException in JFileChooser

    Hello,
    I have a method which shows a JFileChooser to select a save name. After click on the dialog's OK button, sometimes it throws NullPointerException.
    I have checked the thread, and everything runs in EDT, so this should not be the problem.
    The calling code is
    public File getSelectedFile() {
    chooser = new JFileChooser(prefs.get(Configuration.KEY_LAST_SAVED_DIR, null));
    chooser.setSelectedFile(new File(defaultFileName));
    for(ExtensionFileFilter f : fileTypes){
    chooser.addChoosableFileFilter(f);
    if (defaultFilter == null) {
    chooser.setFileFilter(chooser.getAcceptAllFileFilter());
    } else {
    chooser.setFileFilter(defaultFilter);
    // That's where it happens
    int returnVal = chooser.showSaveDialog(parentComponent);
    prefs.put(Configuration.KEY_LAST_SAVED_DIR,chooser.getCurrentDirectory().getAbsolutePath());
    return chooser.getSelectedFile();
    Can you help me spot where the problem is?
    The stack trace is below.
    Thanks for any suggestions.
    Karl
    Exception occurred during event dispatching:
    java.lang.NullPointerException
    at javax.swing.JComponent.repaint(JComponent.java:4728)
    at sun.swing.FilePane$2.repaintListSelection(FilePane.java:114)
    at sun.swing.FilePane$2.repaintSelection(FilePane.java:104)
    at sun.swing.FilePane$2.focusLost(FilePane.java:99)
    at java.awt.AWTEventMulticaster.focusLost(AWTEventMulticaster.java:213)
    at java.awt.Component.processFocusEvent(Component.java:5930)
    at java.awt.Component.processEvent(Component.java:5794)
    at java.awt.Container.processEvent(Container.java:2058)
    at java.awt.Component.dispatchEventImpl(Component.java:4410)
    at java.awt.Container.dispatchEventImpl(Container.java:2116)
    at java.awt.Component.dispatchEvent(Component.java:4240)
    at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1848)
    at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:878)
    at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:551)
    at java.awt.Component.dispatchEventImpl(Component.java:4282)
    at java.awt.Container.dispatchEventImpl(Container.java:2116)
    at java.awt.Component.dispatchEvent(Component.java:4240)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:177)
    at java.awt.Dialog$1.run(Dialog.java:1039)
    at java.awt.Dialog$3.run(Dialog.java:1091)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.awt.Dialog.show(Dialog.java:1089)
    at javax.swing.JFileChooser.showDialog(JFileChooser.java:723)
    at javax.swing.JFileChooser.showSaveDialog(JFileChooser.java:651)
    at io.FileSaver.getSelectedFile(FileSaver.java:141)
    at io.SaverManager.<init>(SaverManager.java:96)
    at io.SaverHolder$SaveSelector.actionPerformed(SaverHolder.java:153)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.java:6038)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
    at java.awt.Component.processEvent(Component.java:5803)
    at java.awt.Container.processEvent(Container.java:2058)
    at java.awt.Component.dispatchEventImpl(Component.java:4410)
    at java.awt.Container.dispatchEventImpl(Container.java:2116)
    at java.awt.Component.dispatchEvent(Component.java:4240)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
    at java.awt.Container.dispatchEventImpl(Container.java:2102)
    at java.awt.Window.dispatchEventImpl(Window.java:2429)
    at java.awt.Component.dispatchEvent(Component.java:4240)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

    My first answer was wrong because the constructor which can handle a null input is the one taking a File. But from the prefs I get a String... So the I need to check first if the string is null and make a File out of it...
    About your idea to use the debugger, I can see where the problem happens (see also the stack trace above). It's when the dialog is showing (Dialog.show has been called) and then, after pressing OK, the Component gets repainted
    java.lang.NullPointerException
    at javax.swing.JComponent.repaint(JComponent.java:4728)
    Unfortunately the problem is only showing once in a while, so it's hard to test solutions...
    Thanks anyway
    Karl

  • Setting default save file in JFileChooser

    Is there a way to set a default file name for the save dialog created by
    JFileChooser.showSaveDialog(null);in order to save the user needing to type something every time?
    Thanks.

    Exactly
    Java keeps ramming classes into the jre that are useful in only a very limited context. At the same time, they can't give us a filedialog that adds the extension onto the returned file... This is something everyone wants, but unfortunately is'nt part of Java. I'm frustrated by it as well (if you can't tell)

  • JFileChooser and file validation

    Hi,
    I use JFileChooser.showSaveDialog(). I neen when user clicks the "Save" button to check if the file already exists and if so to show him warning message and eventually break the approve operation.

    overwrite the approveSelection() method of your JFileChooser. in there you can do your checks before executing super.approveSelection().
    tthomas

  • JFileChooser hangs sometimes

    Hi,
    When I open a JFileChooser save dialog the EDT thread hangs indefinitely. From the stack trace I can see that it is waiting indefinitely when it tries to check if a file is a link or not. This happens only sometimes.The default selected directory(My Documents) does not contain any links or shortcuts.
    Following is the stack trace of AWT-EventQueue thread:
    "AWT-EventQueue-2" prio=6 tid=0x039c9400 nid=0x1210 waiting on condition [0x0400e000..0x0400fb94]
    java.lang.Thread.State: WAITING (parking)
         at sun.misc.Unsafe.park(Native Method)
         - parking to wait for <0x0ae38cd0> (a java.util.concurrent.FutureTask$Sync)
         at java.util.concurrent.locks.LockSupport.park(Unknown Source)
         at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(Unknown Source)
         at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(Unknown Source)
         at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(Unknown Source)
         at java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source)
         at java.util.concurrent.FutureTask.get(Unknown Source)
         at sun.awt.shell.Win32ShellFolderManager2$ComInvoker.invoke(Unknown Source)
         at sun.awt.shell.Win32ShellFolder2.hasAttribute(Unknown Source)
         at sun.awt.shell.Win32ShellFolder2.isLink(Unknown Source)
         - locked <0x0ae38b00> (a sun.awt.shell.Win32ShellFolder2)
         at javax.swing.filechooser.FileSystemView.isFileSystem(Unknown Source)
         at javax.swing.filechooser.FileSystemView.getSystemDisplayName(Unknown Source)
         at javax.swing.plaf.basic.BasicFileChooserUI$BasicFileView.getName(Unknown Source)
         at javax.swing.JFileChooser.getName(Unknown Source)
         at sun.swing.FilePane$FileRenderer.getListCellRendererComponent(Unknown Source)
         at javax.swing.plaf.basic.BasicListUI.updateLayoutState(Unknown Source)
         at javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState(Unknown Source)
         at javax.swing.plaf.basic.BasicListUI.getPreferredSize(Unknown Source)
         at javax.swing.JComponent.getPreferredSize(Unknown Source)
         at javax.swing.ScrollPaneLayout.layoutContainer(Unknown Source)
         at java.awt.Container.layout(Unknown Source)
         at java.awt.Container.doLayout(Unknown Source)
         at java.awt.Container.validateTree(Unknown Source)
         at java.awt.Container.validateTree(Unknown Source)
         at java.awt.Container.validateTree(Unknown Source)
         at java.awt.Container.validateTree(Unknown Source)
         at java.awt.Container.validateTree(Unknown Source)
         at java.awt.Container.validateTree(Unknown Source)
         at java.awt.Container.validateTree(Unknown Source)
         at java.awt.Container.validateTree(Unknown Source)
         at java.awt.Container.validate(Unknown Source)
         - locked <0x0914e040> (a java.awt.Component$AWTTreeLock)
         at java.awt.Dialog.conditionalShow(Unknown Source)
         - locked <0x0914e040> (a java.awt.Component$AWTTreeLock)
         at java.awt.Dialog.show(Unknown Source)
         at javax.swing.JFileChooser.showDialog(Unknown Source)
         at javax.swing.JFileChooser.showSaveDialog(Unknown Source)
         at com.text.SaveApp.launchExportDialog(ActionManager.java:1356)
         at com.text.SaveApp.actionPerformed(ActionManager.java:608)
         at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
         at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
         at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
         at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
         at javax.swing.AbstractButton.doClick(Unknown Source)
         at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
         at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
         at java.awt.Component.processMouseEvent(Unknown Source)
         at javax.swing.JComponent.processMouseEvent(Unknown Source)
         at java.awt.Component.processEvent(Unknown Source)
         at java.awt.Container.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Window.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    "Basic L&F File Loading Thread" prio=6 tid=0x03413800 nid=0x1438 waiting on condition [0x0503f000..0x0503fd94]
    java.lang.Thread.State: WAITING (parking)
         at sun.misc.Unsafe.park(Native Method)
         - parking to wait for <0x0ae389c0> (a java.util.concurrent.FutureTask$Sync)
         at java.util.concurrent.locks.LockSupport.park(Unknown Source)
         at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(Unknown Source)
         at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(Unknown Source)
         at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(Unknown Source)
         at java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source)
         at java.util.concurrent.FutureTask.get(Unknown Source)
         at sun.awt.shell.Win32ShellFolderManager2$ComInvoker.invoke(Unknown Source)
         at javax.swing.plaf.basic.BasicDirectoryModel$LoadFilesThread.run0(Unknown Source)
         at javax.swing.plaf.basic.BasicDirectoryModel$LoadFilesThread.run(Unknown Source)
    "Swing-Shell" daemon prio=6 tid=0x03b8e800 nid=0x7e4 waiting for monitor entry [0x0437f000..0x0437fb14]
    java.lang.Thread.State: BLOCKED (on object monitor)
         at sun.awt.shell.Win32ShellFolder2.isFileSystem(Unknown Source)
         - waiting to lock <0x0ae38b00> (a sun.awt.shell.Win32ShellFolder2)
         at sun.awt.shell.Win32ShellFolder2.equals(Unknown Source)
         at java.util.AbstractList.equals(Unknown Source)
         at java.util.Vector.equals(Unknown Source)
         - locked <0x0ae38b90> (a java.util.Vector)
         at javax.swing.plaf.basic.BasicDirectoryModel$LoadFilesThread$1.call(Unknown Source)
         at javax.swing.plaf.basic.BasicDirectoryModel$LoadFilesThread$1.call(Unknown Source)
         at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
         at java.util.concurrent.FutureTask.run(Unknown Source)
         at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
         at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
         at sun.awt.shell.Win32ShellFolderManager2$ComInvoker$3.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    Let me know if any one has faced similar problems.

    "AWT-EventQueue-2"
    - locked <0x0ae38b00> (a sun.awt.shell.Win32ShellFolder2)
    "Swing-Shell"
    - waiting to lock <0x0ae38b00> (a sun.awt.shell.Win32ShellFolder2)
    That's definitely a symptom of the problem. AWT-EventQueue-2 has not released that lock because it is:
    - parking to wait for <0x0ae38cd0> (a java.util.concurrent.FutureTask$Sync)
    Can you find that object "0x0ae38cd0" somewhere else in the thread dump? It might be revealing to see who has ahold of it and why they haven't released it yet.

  • Outputting to a text file.

    Hey guys and gals,
    Im doing a program for work that is a form you type in, select save and it stores the data to a file. I have 2 problems. FIRST i need to know how to change the font. SECOND how do i put in tabs, returns using out.write(...);
    The goal is to output a form to a text file that can be saved, printed. Right now it all runs together in the .txt or .doc file that it makes.
    thanks bunches
    package hrform;
    // imports
    import java.awt.Font;
    import java.awt.*;
    import java.io.*;
    import javax.swing.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import javax.swing.event.*;
    import java.awt.Font;
    public class form extends JFrame implements ActionListener
    //declare text boxes, buttons, radiobuttons
    private JRadioButton jrbThree, jrbSix;
    //private ButtonGroup btg = new ButtonGroup();
    private JButton jbtSave;
    private JTextField jtfEmployee, jtfDateofhire;
    private JTextField jtfDatecompleted, jtfJobtitle;
    private JFileChooser jFileChooser = new JFileChooser();
    private JTextField jtfCurrentpay, jtfDateofincrease, jtfAmount;
    private JTextField jtfAcceptible, jtfExemplary, jtfImprovement, jtfDependability;
    private JTextField jtfPersonality, jtfGoals;
    /** Main Method*/
    public static void main(String [] args)
    form frame = new form();
    //frame.setDefault(closeOperation(JFrame.EXIT_ON_CLOSE));
    frame.setSize(800,580);
    frame.setVisible(true);
    /**Default Constructor*/
    public form()
    Color defaultColor = Color.red;
    setTitle("Employee Evaluation Form");
    JPanel p1 = new JPanel();
    p1.setLayout(new FlowLayout(FlowLayout.LEFT,10,10));
    setColor (Color.lightGray);
    p1.add(new JLabel("Employee Name:"));
    p1.add(jtfEmployee = new JTextField(11));
    p1.add(new JLabel("Date of Hire:"));
    p1.add(jtfDateofhire = new JTextField(10));
    p1.add(new JLabel("Date Completed by Employee"));
    p1.add(jtfDatecompleted = new JTextField(10));
    // panel p2 for radio buttons
    JPanel p2 = new JPanel();
    p2.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10));
    p2.add(new JLabel("Job Title: "));
    p2.add(jtfJobtitle = new JTextField(20));
    p2.add(new JLabel("Current Rate of Pay"));
    p2.add(jtfCurrentpay = new JTextField(10));
    p2.add(new JLabel("Date of Last Increase: "));
    p2.add(jtfDateofincrease = new JTextField(8));
    p2.add(new JLabel("Amount of Last Increase: "));
    p2.add(jtfAmount = new JTextField(70));
    p2.add(new JLabel("Has displayed an acceptable level of performance these areas: "));
    p2.add(jtfAcceptible = new JTextField(70));
    p2.add(new JLabel("Has shown EXEMPLARY performace in these areas: "));
    p2.add(jtfExemplary = new JTextField(70));
    p2.add(new JLabel("Areas for Improvement: "));
    p2.add(jtfImprovement = new JTextField(70));
    p2.add(new JLabel("Dependability(Focus on attendance, punctuality, and attentiveness): "));
    p2.add(jtfDependability = new JTextField(70));
    p2.add(new JLabel("Personality(Focus on ability to work for and with others): "));
    p2.add(jtfPersonality = new JTextField(70));
    p2.add(new JLabel("GOALS FOR NEXT QUARTER: "));
    p2.add(jtfGoals = new JTextField(70));
    p2.add(jbtSave = new JButton());
    jbtSave.setText("Save");
    //set default directory
    jFileChooser.setCurrentDirectory(new File("F:WPDOCS/Personne"));
    //Set flowlayout for the fram
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(p1, BorderLayout.NORTH);
    getContentPane().add(p2, BorderLayout.CENTER);
    // Register Listeners
    jbtSave.addActionListener(this);
    /** Handle event */
    public void actionPerformed(ActionEvent e)
    String actionCommand= e.getActionCommand();
    if (e.getSource() instanceof JButton)
    if ("Save".equals(actionCommand))
    Save();
    /** Save file*/
    private void Save()
    if(jFileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION)
    Save(jFileChooser.getSelectedFile());
    private void Save(File file)
    try
    Font helv = new Font("Helvetica", Font.BOLD, 16);
    Font courier = new Font("Courier", Font.BOLD, 24);
    Color defaultColor = Color.cyan;
    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
    out.write(new JLabel(" ").getText().getBytes());
    //out.setFont("SansSerif",Font.BOLD,14);
    out.write(new JLabel("TMC Orthopedic - EMPLOYEE PERFORMANCE EVALUATION").getText().getBytes());
    out.write(new JLabel(" ").getText().getBytes());
    out.write(new JLabel("Employee Name: ").getText().getBytes());
    byte[] b = (jtfEmployee.getText()).getBytes();
    out.write(b,0,b.length);
    out.write(new JLabel(" ").getText().getBytes());
    out.write(new JLabel("Date of Hire: ").getText().getBytes());
    out.write(new JLabel().getText().getBytes());
    byte[] c = (jtfDateofhire.getText()).getBytes();
    out.write(c,0,c.length);
    out.write(new JLabel(" ").getText().getBytes());
    out.write(new JLabel("Date Completed by Employee: ").getText().getBytes());
    //out.writeChars(\n);
    byte[] d = (jtfDatecompleted.getText().getBytes());
    out.write(d,0,d.length);
    byte[] e = (jtfJobtitle.getText().getBytes());
    out.write(new JLabel(" ").getText().getBytes());
    out.write(new JLabel("Job Title: ").getText().getBytes());
    out.write(e,0,e.length);
    out.write(new JLabel(" ").getText().getBytes());
    out.write(new JLabel("Current Pay: ").getText().getBytes());
    byte[] f = (jtfCurrentpay.getText().getBytes());
    out.write(f,0,f.length);
    out.write(new JLabel(" ").getText().getBytes());
    byte[] g = (jtfDateofincrease.getText().getBytes());
    out.write(new JLabel("Date of Last Increase: ").getText().getBytes());
    out.write(g,0,g.length);
    out.write(new JLabel(" ").getText().getBytes());
    byte[] h = (jtfAmount.getText().getBytes());
    out.write(new JLabel("Amount Of Last Increase").getText().getBytes());
    out.write(h,0,h.length);
    out.write(new JLabel(" ").getText().getBytes());
    out.write(new JLabel("Has displayed an acceptable level of performance in these areas: ").getText().getBytes());
    byte[] i = jtfAcceptible.getText().getBytes();
    out.write(i,0,i.length);
    out.write(new JLabel(" ").getText().getBytes());
    out.write(new JLabel("Has displayed an exemplary level of performance in the following areas: ").getText().getBytes());
    byte[] j = jtfExemplary.getText().getBytes();
    out.write(j,0,j.length);
    out.write(new JLabel(" ").getText().getBytes());
    out.write(new JLabel("Areas for improvement").getText().getBytes());
    byte[] k = jtfImprovement.getText().getBytes();
    out.write(k,0,k.length);
    out.write(new JLabel(" ").getText().getBytes());
    out.write(new JLabel("Dependability(Focus on attendance, punctuality, and attentiveness): ").getText().getBytes());
    byte[] l = jtfDependability.getText().getBytes();
    out.write(l,0,l.length);
    out.write(new JLabel(" ").getText().getBytes());
    out.write(new JLabel("Personality (Forcus on ability to work for and with others): ").getText().getBytes());
    byte[] m = jtfPersonality.getText().getBytes();
    out.write(m,0,m.length);
    out.write(new JLabel(" ").getText().getBytes());
    out.write(new JLabel("GOALS FOR NEXT QUARTER: ").getText().getBytes());
    byte[] n = jtfGoals.getText().getBytes();
    out.write(n,0,n.length);
    out.close();
    catch(IOException ex)

    I tried both of these and i get an error.
    "form.java": Error #: 300 : method write(java.lang.String) not found in class java.io.BufferedOutputStream at line 136, column 15
    Do i need to include something else???
    Thanks
    To insert a tab, use out.write("\t"). To insert a newline (crossplatform), use out.write(System.getProperty("line.separator")).
    HTH!
    :o)

  • In Need Of Divine Intervention

    Need some help with this. I can't seem to get the "browse" button to browse my PC for images in the Upload frame. The "Cancel" button is closing the entire programme instead of just the Upload frame.
    Anyone know the problem? i just started java bout 3 months ago and still a noob at it =(
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.util.List;
    import javax.imageio.ImageIO;
    import javax.imageio.stream.FileImageInputStream;
    import javax.swing.*;
    import javax.swing.filechooser.*;
    public class PhotoAlbum extends JFrame
      implements ActionListener
      // Menu items Upload, Save, exit, and About
      private JMenuItem jmiUpload, jmiSave,jmiExit, jmiAbout, ttUpload;
      private JButton jbtnEditlabel , jbtnSavelabel,browse,cancel;
      // Text area for displaying and editing text files
         private JPanel jta,over;
         Image image;     
         SlidePanel slidePanel;     
         JComboBox slides;
         JFrame f;
         JFileChooser fileChooser;
      // Status label for displaying operation status
      private JLabel jlblStatus = new JLabel();
      // Scrolling
      private JScrollPane scrollPane = new JScrollPane();
      // File dialog box
      private JFileChooser jFileChooser = new JFileChooser();
      // Radio Buttons
      private JRadioButtonMenuItem jmiSlideshow , jmiThumbnail;
      //JPanels
      private JPanel head , body , low;
      /**Main method*/
      public static void main(String[] args)
           JFrame.setDefaultLookAndFeelDecorated(true);
        PhotoAlbum frame = new PhotoAlbum();
        frame.setSize(600, 300);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
         frame.setLocationRelativeTo( null );
      public PhotoAlbum()
        setTitle("Photo Library");
        // Create a menu bar mb and attach to the frame
        JMenuBar mb = new JMenuBar();
        setJMenuBar(mb);
        // Add a "File","Help" and "View" menu in mb
        JMenu fileMenu = new JMenu("File");
        mb.add(fileMenu);
        JMenu viewMenu = new JMenu("View");
         mb.add(viewMenu);
         JMenu helpMenu = new JMenu("Help");
         mb.add(helpMenu);
              JPanel jta = new JPanel();
         //Setting a scrolling pane for jta
         jta.setOpaque( false );//making jta transparent
         jta.setPreferredSize( new Dimension(1200, 1200) );
        // Create and add menu items to the menu
        fileMenu.add(ttUpload = new JMenuItem("Upload"));
        fileMenu.add(jmiSave = new JMenuItem("Save"));
        fileMenu.addSeparator();
        fileMenu.add(jmiExit = new JMenuItem("Exit"));
        helpMenu.add(jmiAbout = new JMenuItem("About"));
    //    group.add(jmiThumbnail);group.add(jmiSlideshow);
        viewMenu.add(jmiThumbnail = new JRadioButtonMenuItem("Thumbnail"));
        viewMenu.add(jmiSlideshow = new JRadioButtonMenuItem("Slideshow"));
        getContentPane().add(scrollPane);
         //  "Low Panel"with a white background and placing "jbtnEditlabel" into it
         low = new JPanel();
         low.setBackground(Color.white);
         low.add(jbtnEditlabel = new JButton("Edit Labels"));
         //  "Low Panel     
         body = new JPanel();
         jta.setBackground(Color.white);
         // Creating edit label button
         getContentPane().add(low, BorderLayout.SOUTH);
        // Set default directory to the current directory
        jFileChooser.setCurrentDirectory(new File("."));
        // Set BorderLayout for the frame
        getContentPane().add(new JScrollPane(jta),BorderLayout.CENTER);
        getContentPane().add(jlblStatus, BorderLayout.NORTH);
        // Register listeners
        ttUpload.addActionListener(this);
        jmiSave.addActionListener(this);
        jmiAbout.addActionListener(this);
        jmiExit.addActionListener(this);
        jmiSlideshow.addActionListener(this);
        jmiThumbnail.addActionListener(this);
        jbtnEditlabel.addActionListener(this);
      /**Handle ActionEvent for menu items*/
      public void actionPerformed(ActionEvent e)
        String actionCommand = e.getActionCommand();
        if (e.getSource() instanceof JMenuItem)
          if ("Upload".equals(actionCommand))
            upload();
          else if ("Save".equals(actionCommand))
            save();
          else if ("About".equals(actionCommand))
            JOptionPane.showMessageDialog(this,"Insert Images using Upload or edit the labels of present images.",
            "About This Demo",JOptionPane.INFORMATION_MESSAGE);
          else if ("Exit".equals(actionCommand))
            System.exit(0);
          else if ("Slideshow".equals(actionCommand))
            jmiSlideshow();       
          else if ("Thumbnail".equals(actionCommand))
            jmiThumbnail();
      /**Save file*/
      private void save()
        if (jFileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION)
          save(jFileChooser.getSelectedFile());
      /**Save file with specified File instance*/
      private void save(File file)
        try
          // Write the text in jta to the specified file
          BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
    //      byte[] b = (jta.getText()).getBytes();
    //      out.write(b, 0, b.length);
          out.close();
          // Display the status of the save file operation in jlblStatus
          jlblStatus.setText(file.getName()  + " Saved ");
        catch (IOException ex)
          jlblStatus.setText("Error saving " + file.getName());
         /**jmiSlideshow file*/
      private void jmiSlideshow()
      /**jmiThumbnail file*/
      private void jmiThumbnail()
            private void upload()
                   /* Set title of frame to Upload File*/
                   String frameTitle="Upload File";
                   final JFrame upload= new JFrame(frameTitle);
                   /* Creating "file" label / txtfield and uploadPanel */
                   JPanel uploadPanel=new JPanel();
                   JLabel xfile=new JLabel("File");
                   JTextField input=new JTextField(20);
                   /* Creating buttons and btm panel*/
                   JPanel  buttonPanel=new JPanel();
                   JButton jbtnCancel=new JButton("Cancel");
                   JButton jbtnOk=new JButton("OK");
                   JButton jbtnBrowse=new JButton("Browse");
                   /* Adding buttons and txtfields into uploadPanel*/
                   uploadPanel.add(xfile);
                   uploadPanel.add(input);
                   uploadPanel.add(jbtnBrowse);               
                   uploadPanel.add(jbtnCancel);
                   uploadPanel.add(jbtnOk);
                   /* Adding uploadPanel into upload*/
                   upload.getContentPane().add(uploadPanel);
                   /* Set size/visibilty/ and close operations*/
                   upload.setSize(550, 200);
                   upload.setVisible(true);
                   upload.setDefaultCloseOperation(EXIT_ON_CLOSE);
                   upload.addWindowListener(new WindowAdapter()
                        public void windowClosing(WindowEvent e)
                             upload.setVisible(false);
                   /* Adding listeners for the buttons in Upload()*/
                   jbtnCancel.addActionListener(new jbtnCancelListener());          
                   jbtnBrowse.addActionListener(new jbtnBrowseListener());
          /* Cancel button */
               class jbtnCancelListener implements ActionListener
              public void actionPerformed(ActionEvent e)
                   System.exit(0);
          /**Browse button*/
               class jbtnBrowseListener implements ActionListener
              public void actionPerformed(ActionEvent e)
              if(fileChooser.showOpenDialog(f) == JFileChooser.APPROVE_OPTION)
                File file = fileChooser.getSelectedFile();
                     if(hasValidExtension(file))
                    Slide slide = new Slide(file);
                    slides.addItem(slide);
                    slides.setSelectedItem(slide);
                    slidePanel.addImage(slide.getFile());
             public boolean hasValidExtension(File file)
                 String[] okayExtensions = { "gif", "jpg", "png" };
                 String path = file.getPath();
                 String ext = path.substring(path.lastIndexOf(".") + 1).toLowerCase();
                 for(int j = 0; j < okayExtensions.length; j++)
                if(ext.equals(okayExtensions[j]))
                return true;
                 return false;
         class Slide
        File file;
        public Slide(File file)
            this.file = file;
        public File getFile()
            return file;
        public String toString()
            return file.getName();
    class SlidePanel extends JPanel
        List<BufferedImage> images;
        int count;
        boolean keepRunning;
        Thread animator;
        public SlidePanel()
            images = Collections.synchronizedList(new ArrayList<BufferedImage>());
            count = 0;
            keepRunning = false;
            setBackground(Color.white);
        protected void paintComponent(Graphics g)
            super.paintComponent(g);
            int w = getWidth();
            int h = getHeight();
            if(images.size() > 0)
                BufferedImage image = images.get(count);
                int imageWidth = image.getWidth();
                int imageHeight = image.getHeight();
                int x = (w - imageWidth)/2;
                int y = (h - imageHeight)/2;
                g.drawImage(image, x, y, this);
        private Runnable animate = new Runnable()
            public void run()
                while(keepRunning)
                    if(images.size() == 0)
                        stop();
                        break;
                    count = (count + 1) % images.size();
                    repaint();
                    try
                        Thread.sleep(1000);
                    catch(InterruptedException ie)
                        System.err.println("animate interrupt: " + ie.getMessage());
                repaint();
        public void start()
            if(!keepRunning)
                keepRunning = true;
                animator = new Thread(animate);
                animator.start();
        public void stop()
            if(keepRunning)
                keepRunning = false;
                animator = null;
        public void addImage(File file)
            try
                FileImageInputStream fiis = new FileImageInputStream(file);
                images.add(ImageIO.read(fiis));                             
            catch(FileNotFoundException fnfe)
                System.err.println("file: " + fnfe.getMessage());
            catch(IOException ioe)
                System.err.println("read: " + ioe.getMessage());
        public void removeImage(int index)
            images.remove(index);
    }

    not got time to look much but replace the System.exit(0) with this.dispose() will close the frame instead of closing the whole application.
    http://www.magiksafe.com

  • Suggest a filename extension in a save file dialog

    Hello guys,
    does any of you know, how to suggest the user a certain filename extension in a save file dialog?
    I'm using both the normal save file dialog:
         javax.swing.JFileChooser.showSaveDialog,
    and the Java Web Start save file dialog:
         javax.jnlp.FileSaveService.saveFileDialog.
    For both ways I seem not to be able to suggest the user a certain extension for the filename.
    For the normal dialog, I call setFileFilter on the JFileChooser instance.
    The filter shows up in the dialog, and is used by default, but when the user types a name and approves, the returned filename does not have the extension added.
    Of course I can add the extension programmaticaly, but not when inside the JAWS sandbox.
    For the JAWS dialog, I pass an array containing my extension, but it is ignored as if I didn't specify any extensions. The API specs already say that this parameter "might be ignored by the JNLP Client".
    So how to tell the user what extension to use?
    More people must have encountered this problem.
    I'm making an application that saves and opens xml files and exports html files.
    I'm using this code to test the behavior:import java.io.ByteArrayInputStream;
    import java.io.File;
    import javax.jnlp.FileContents;
    import javax.jnlp.FileSaveService;
    import javax.jnlp.ServiceManager;
    import javax.jnlp.UnavailableServiceException;
    import javax.swing.JFileChooser;
    import javax.swing.filechooser.FileFilter;
    public class ChooseFile
        static final String[] EXTENSIONS = { "xml" };
        static final String DESCRIPTION = "XML files";
        public static void main(String[] args)
         try {
             ServiceManager.lookup("javax.jnlp.FileOpenService");
             // we're running with JAWS
             System.out.println("JAWS filechooser:");
             System.out.println(choose_JAWS());
         catch (UnavailableServiceException x)
             // we're NOT running with JAWS
             System.out.println("normal filechooser:");
             System.out.println(choose_normal());
        static String choose_normal()
         JFileChooser fc = new JFileChooser();
         fc.setFileFilter(new CustomFileFilter(EXTENSIONS, DESCRIPTION));
         if (JFileChooser.APPROVE_OPTION == fc.showSaveDialog(null))
             return "selected " + fc.getSelectedFile().getName();
         else
             return "cancelled";
        static String choose_JAWS()
         try {
             FileSaveService fos = (FileSaveService)ServiceManager.lookup(
                         "javax.jnlp.FileSaveService");
             ByteArrayInputStream stream = new ByteArrayInputStream(new byte[] {});
             FileContents fc = fos.saveFileDialog(null, EXTENSIONS, stream, null);
             if (fc != null)
              return "selected " + fc.getName();
             else
              return "cancelled";
         } catch (Exception x)
             x.printStackTrace();
            return "";
    class CustomFileFilter extends FileFilter
        String[] extensions;
        String description;
        public CustomFileFilter(String[] extensions, String description)
         this.extensions = extensions;
         this.description = description;
        public boolean accept(File f)
         if (f.isDirectory())
             return true;
         String extension = getExtension(f);
            if (extension == null)
                return false;
         for (int i=extensions.length; i-->0; )
             if (extension.equals(extensions))
              return true;
         return false;
    public String getDescription()
         return description;
    private String getExtension(File f)
    String ext = null;
    String s = f.getName();
    int i = s.lastIndexOf('.');
    if (i > 0 && i < s.length() - 1)
    ext = s.substring(i+1).toLowerCase();
    return ext;
    }Any help is greatly appreciated!
    Tom Jansen

    @tjacobs01
    Hi Tom,
    I have a question regarding your classes
    tjacobs.ui.fc.FileExtensionFilter and
    tjacobs.ui.fc.FileChooser.
    When I look at your code, I see the filename extension is appended in showSaveDialog:     public int showSaveDialog(Component c) {
                        setSelectedFile(new File(f.getAbsolutePath() + "." + ((FileExtensionFilter)filter).getType()));
        }It gets the extension by calling getType on the filter. But getType is implemented as:    public String getType () {
            return mExtensionList.get(0).toString();
        }So this returns the first type in the list. It does not check what filetype is selected by the combobox.
    Am I missing something?
    Also, in getDescription:    public String getDescription() {
            if (mDesc == null) {
                mDesc = "";
                for (int i = 0; i < mExtensionList.size(); i++) {
                    mDesc += (i != 0 ? ", " : "") + "." + mExtensionList.get(0).toString();
                mDesc+= " files";
            return mDesc;
        }you seem to iterate through the list, but only take the first entry every iteration.
    Can you explain mExtensionList.get(0)?
    Do you know how to test what type is selected in the JFileChooser's combobox?

  • Save capture screen.

    //get the file name and it's path from the user's input.
    JFileChooser jFileChooser = new JFileChooser();
    jFileChooser.setDialogTitle("Save Screen Dialog Box");
    jFileChooser.showSaveDialog(null);
    fileNamePath = jFileChooser.getSelectedFile().getCanonicalPath();
    String fileName = jFileChooser.getSelectedFile().getName();
    BufferedImage rectangle;
    Robot robot = new Robot();
    rectangle = robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
    OutputStream os = new FileOutputStream(fileNamePath);
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(os);
    encoder.encode(rectangle);
    Any one know any function to delay system or somthing that i can fix my bug.
    The code above when i save the capture screen then the save dialog is captured too,
    but i dont want it capture the dialog , just capture only screen.
    i try some function like sleep(2000) before i capture but dont help , any one have any idea please help me out,
    thank you very much .
    Jenny,.

    I think the problem might be that the frame hasn't had time to repaint itself before the Robot starts.
    From the Robot API I see the following method:
    public void waitForIdle() - Waits until all events currently on the event queue have been processed
    There is also a delay() method that might do something.
    This is just a guess, I haven't tested it.

  • Inner class access to its creator

    Hi there,
    From a subclass of Action I have created as a (non-static) inner class of a JFrame, I wish to reference the parent JFrame in a JFileChooser invocation, so something like:JFileChooser.showSaveDialog(**this**);with **this** being the parent JFrame.
    One option I can think of is to pass through "this" when I instantiate the action, but I wondered if there was a language construction that provided this information directly.
    I tried a search through the forums using "parent of an inner class" but found nothing useful. Is there a mechanism to provide this, or is passing "this" through to the inner class the only option?
    Thanks for any help you can provide.
    Tim

    To access wrapper instance of inner class, you can use WRAPPER_INSTANCE_CLASS.this keyword.
    For example:
    public class a {
       int value = 0;
       public void doSomething() {
          Object dummy = new Object() {
              public String toString() {
                  a.this.setSomething(10);
                  return a.this.toString();
          System.out.println(dummy);
       public void setSomething(int x) {
          value = x;
       public String toString() {
          return "class a, the value now is " + value;
       public static void main (String s[]) {
           new a().doSomething();
    }note that I use a.this.setSomething(10);
    a is the wrapper class, so a.this refers to the wrapper instance, not current instance.
    rgds,
    Alex

  • Screenshot Processing

              saveButton.addActionListener
                   new ActionListener()
                        public void actionPerformed(ActionEvent event)
                             sig1.setVisible(true);
                             sig2.setVisible(true);
                             sig3.setVisible(true);
                             saveButton.setVisible(false);
                             try
                                  Toolkit toolkit = Toolkit.getDefaultToolkit();
                                  Dimension screenSize = toolkit.getScreenSize();
                                  Rectangle screenRect = new Rectangle(screenSize);
                                  Robot robot = new Robot();
                                  BufferedImage image = robot.createScreenCapture(screenRect);
                                  JFileChooser jFileChooser = new JFileChooser();
                                  int returnVal = jFileChooser.showSaveDialog(saveButton);
                                  if(returnVal == JFileChooser.APPROVE_OPTION)
                                       ImageIO.write(image, "jpg", new File(jFileChooser.getSelectedFile()+".jpg"));
                             catch(Exception e)
                                  System.out.println(e);
                             sig1.setVisible(false);
                             sig2.setVisible(false);     
                             sig3.setVisible(false);
                             saveButton.setVisible(true);
              );I'm using the above code to capture and save a screenshot. However, I have two "problems." First, the screenshot saved is not showing sig1, sig2, or sig3 and is still showing saveButton. When my filechooser pops up, the screen looks the way I want it (showing the sigs and not the button), but the screenshot is showing the "old" screen. Secondly, my screenshot is getting my entire desktop, and I would like it to only get the currently open Java window. Can anyone provide some suggestions? Thanks a lot!

    This is my standard response to a question like
    this:
    If you need further help then you need to create a
    [url
    http://homepage1.nifty.com/algafield/sscce.html]Short,
    Self Contained, Compilable and Executable, Example
    Program (SSCCE) that demonstrates the incorrectbehaviour, because I can't guess exactly what you are
    doing based on the information provided.
    And don't forget to use the [url
    http://forum.java.sun.com/help.jspa?sec=formatting]Cod
    e Formatting Tags so the code retains its
    original formatting.
    Because I guess I don't understand your problem. I
    just reran my ScreenImage class. I changed the code
    so that when you click on the "Create Images" button
    I do the following:
    a) set the button invisible
    b) start a new Thread
    c) in the Thread I sleep for 50ms
    d) create an image of the frame
    The resulting image does not contain the button. I
    though you where trying to remove some components
    from the frame before taking an image of the frame.
    I believe I've done those 4 steps in my code. Here is the current code I'm using, with comments where I believe I am doing a, b, c, and d:
              saveButton.addActionListener
                   new ActionListener()
                        public void actionPerformed(ActionEvent event)
                             sig1.setVisible(true); // a) setting fields visible and button invisible
                             sig2.setVisible(true);
                             sig3.setVisible(true);
                             saveButton.setVisible(false);
                             location = getLocationOnScreen();
                             dimension = getSize();
                             EvalRunnable evalRunnable = new EvalRunnable();
                             Thread t = new Thread(evalRunnable);
                             SwingUtilities.invokeLater(evalRunnable); // b) starting new thread (class EvalRunnable below)
                             sig1.setVisible(false);
                             sig2.setVisible(false);     
                             sig3.setVisible(false);
                             saveButton.setVisible(true);
    public class EvalRunnable implements Runnable
         public void run()
              try
                            Thread.sleep(50); // c) putting thread to sleep for 50ms
                   Rectangle screen = new Rectangle(ViewEval.location, ViewEval.dimension);
                   Robot robot = new Robot();
                   BufferedImage image = robot.createScreenCapture(screen); // d) creating image of the frame
                   JFileChooser jFileChooser = new JFileChooser();
                   int returnVal = jFileChooser.showSaveDialog(ViewEval.saveButton);
                   if(returnVal == JFileChooser.APPROVE_OPTION)
                        ImageIO.write(image, "jpg", new File(jFileChooser.getSelectedFile()+".jpg"));
              catch(Exception e)
                   System.out.println(e);
    }So I think I did those 4 steps you recommend. Did I do anything wrong? Thanks a lot for the help camickr and others.

  • Lets put it this way: The best program developed in Java

    does anyone have any suggestions??

    import java.awt.Font;
    import java.awt.*;
    import java.io.*;
    import javax.swing.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import javax.swing.event.*;
    import java.awt.Font;
    import java.awt.event.*;
    public class form extends JFrame implements ActionListener
          //declare text boxes, buttons, radiobuttons
          private JButton jbtSave;
          private JTextField jtfEmployee, jtfDateofhire;
          private JTextField jtfDatecompleted, jtfJobtitle;
          private JFileChooser jFileChooser = new JFileChooser();
          private JTextField jtfCurrentpay, jtfDateofincrease, jtfAmount;
          private JTextField jtfAcceptible, jtfExemplary, jtfImprovement, jtfDependability;
          private JTextField jtfPersonality, jtfGoals, jtfReview, jtfSreview;
          private ButtonGroup btguno = new ButtonGroup();
          /** Main Method*/
          public static void main(String [] args)
              form frame = new form();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setSize(800,580);
              frame.setVisible(true);
          /**Default Constructor*/
          public form()
              //Panel one
              setTitle("Employee Evaluation Form");
              JPanel p1 = new JPanel();
              p1.setLayout(new FlowLayout(FlowLayout.LEFT,10,10));
              p1.add(new JLabel("Employee Name:"));
              p1.add(jtfEmployee = new JTextField(11));
              p1.add(new JLabel("Date of Hire:"));
              p1.add(jtfDateofhire = new JTextField(10));
              p1.add(new JLabel("Date Completed by Employee:"));
              p1.add(jtfDatecompleted = new JTextField(10));
              // panel p2
              JPanel p2 = new JPanel();
              p2.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10));
              p2.add(new JLabel("Position: "));
              p2.add(jtfJobtitle = new JTextField(10));
              p2.add(new JLabel("Current Rate of Pay:"));
              p2.add(jtfCurrentpay = new JTextField(5));
              p2.add(new JLabel("Date of Last Increase: "));
              p2.add(jtfDateofincrease = new JTextField(5));
              p2.add(new JLabel("Amt of Last Increase:"));
              p2.add(jtfAmount = new JTextField(4));
              p2.add(new JLabel("Type of Review (3-Month, 6-Month, 9-Month, Semi-Annual, Annual, Merit):"));
              p2.add(jtfReview = new JTextField(10));
              p2.add(new JLabel("New Sales (1-Month, 2-Month, 3-month, 4-Month, 5-Month):                          "));
              p2.add(jtfSreview = new JTextField(10));
              p2.add(new JLabel("Has displayed an ACCEPTABLE level of performance these areas: "));
              p2.add(jtfAcceptible = new JTextField(70));
              p2.add(new JLabel("Has shown EXEMPLARY performace in these areas: "));
              p2.add(jtfExemplary = new JTextField(70));
              p2.add(new JLabel("Areas for Improvement: "));
              p2.add(jtfImprovement = new JTextField(70));
              p2.add(new JLabel("Dependability (Focus on attendance, punctuality, and attentiveness): "));
              p2.add(jtfDependability = new JTextField(70));
              p2.add(new JLabel("Personality (Focus on ability to work for and with others): "));
              p2.add(jtfPersonality = new JTextField(70));
              p2.add(new JLabel("GOALS FOR NEXT QUARTER: "));
              p2.add(jtfGoals = new JTextField(70));
              p2.add(jbtSave = new JButton());
              jbtSave.setText("SAVE you MUST type .doc ");
              p2.add(new JLabel("Please Save as:  Employee Name MMDDYY.doc"));
              //set default directory
              jFileChooser.setCurrentDirectory(new File("F:"));
              jFileChooser.setCurrentDirectory(new File("F:WPDOCS/Personne/Performance Reviews"));
              //Set flowlayout for the frame
              getContentPane().setLayout(new BorderLayout());
              getContentPane().add(p1, BorderLayout.NORTH);
              getContentPane().add(p2, BorderLayout.CENTER);
              // Register Listeners
              jbtSave.addActionListener(this);
          /** Handle event */
          public void actionPerformed(ActionEvent e)
             if (e.getSource() == jbtSave)
                Save();
          /** Save file*/
          private void Save()
          int result = jFileChooser.showSaveDialog(this);
             if(result == JFileChooser.APPROVE_OPTION){
              Save(jFileChooser.getSelectedFile());   }
          private void Save(File file)
            try
              BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
              out.write(new JLabel("                    ").getText().getBytes());
              out.write(new JLabel("TMC ORTHOPEDIC - EMPLOYEE PERFORMANCE EVALUATION").getText().getBytes());
              out.write(("\r").getBytes());
              out.write(("\r").getBytes());
              out.write(new JLabel("EMPLOYEE NAME: ").getText().getBytes());
              byte[] b = (jtfEmployee.getText()).getBytes();
              out.write(("\t").getBytes());
              out.write(("\t").getBytes());
              out.write(("\t").getBytes());
              out.write(("\t").getBytes());
              out.write(b,0,b.length);
              out.write(("\r").getBytes());
              out.write(new JLabel("DATE OF HIRE: ").getText().getBytes());
              out.write(new JLabel().getText().getBytes());
              out.write(("\t").getBytes());
              out.write(("\t").getBytes());
              out.write(("\t").getBytes());
              out.write(("\t").getBytes());
              byte[] c = (jtfDateofhire.getText()).getBytes();
              out.write(c,0,c.length);
              out.write(("\r").getBytes());
              out.write(new JLabel("DATE COMPLETED BY EMPLOYEE: ").getText().getBytes());
              out.write(("\t").getBytes());
              out.write(("\t").getBytes());
              byte[] d = (jtfDatecompleted.getText().getBytes());
              out.write(d,0,d.length);
              byte[] e = (jtfJobtitle.getText().getBytes());
              out.write(("\r").getBytes());
              out.write(new JLabel("JOB TITLE: ").getText().getBytes());
              out.write(("\t").getBytes());
              out.write(("\t").getBytes());
              out.write(("\t").getBytes());
              out.write(("\t").getBytes());
              out.write(("\t").getBytes());
              out.write(e,0,e.length);
              out.write(("\r").getBytes());
              out.write(new JLabel("REVIEW TYPE: ").getText().getBytes());
              out.write(("\t").getBytes());
              out.write(("\t").getBytes());
              out.write(("\t").getBytes());
              out.write(("\t").getBytes());
              //out.write(("\t").getBytes());
              byte[] r =(jtfReview.getText().getBytes());
              out.write(r,0,r.length);
              out.write(("\r").getBytes());
              out.write(new JLabel("NEW SALES: ").getText().getBytes());
              out.write(("\t").getBytes());
              out.write(("\t").getBytes());
              out.write(("\t").getBytes());
              out.write(("\t").getBytes());
              out.write(("\t").getBytes());
              byte[] s =(jtfSreview.getText().getBytes());
              out.write(s,0,s.length);
              out.write(("\r").getBytes());
              out.write(new JLabel("CURRENT PAY: ").getText().getBytes());
              out.write(("\t").getBytes());
              out.write(("\t").getBytes());
              out.write(("\t").getBytes());
              out.write(("\t").getBytes());
              //out.write(("\t").getBytes());
              byte[] f = (jtfCurrentpay.getText().getBytes());
              out.write(f,0,f.length);
              out.write(("\r").getBytes());
              out.write(new JLabel("DATE OF LAST INCREASE: ").getText().getBytes());
              byte[] g = (jtfDateofincrease.getText().getBytes());
              out.write(("\t").getBytes());
              out.write(("\t").getBytes());
              out.write(("\t").getBytes());
              out.write(g,0,g.length);
              out.write(("\r").getBytes());
              out.write(new JLabel("AMOUNT OF LAST INCREASE: ").getText().getBytes());
              byte[] h = (jtfAmount.getText().getBytes());
              out.write(("\t").getBytes());
              out.write(("\t").getBytes());
              out.write(h,0,h.length);
              out.write(("\r").getBytes());
              out.write(("\r").getBytes());
              out.write(("HAS DISPLAYED AN ACCEPTABLE LEVEL OF PERFORMANCE IN THESE AREAS: ").getBytes());
              out.write(("\r").getBytes());
              byte[] i = jtfAcceptible.getText().getBytes();
              out.write(i,0,i.length);
              out.write(("\r").getBytes());
              out.write(("\r").getBytes());
              out.write(("HAS DISPLAYED AN EXEMPLARY LEVEL OF PERFORMANCE IN THE FOLLOWING AREAS: ").getBytes());
              out.write(("\r").getBytes());
              byte[] j = jtfExemplary.getText().getBytes();
              out.write(j,0,j.length);
              out.write(("\r").getBytes());
              out.write(("\r").getBytes());
              out.write(new JLabel("AREAS FOR IMPROVEMENT: ").getText().getBytes());
              out.write(("\r").getBytes());
              byte[] k = jtfImprovement.getText().getBytes();
              out.write(k,0,k.length);
              out.write(("\r").getBytes());
              out.write(("\r").getBytes());
              out.write(new JLabel("DEPENDABILITY(FOCUS ON ATTENDANCE, PUNCTUALITY, AND ATTENTIVENESS): ").getText().getBytes());
              out.write(("\r").getBytes());
              byte[] l = jtfDependability.getText().getBytes();
              out.write(l,0,l.length);
              out.write(("\r").getBytes());
              out.write(("\r").getBytes());
              out.write(("PERSONALITY (FOCUS ON ABILITY TO WORK FOR AND WITH OTHERS): ").getBytes());
              byte[] m = jtfPersonality.getText().getBytes();
              out.write(("\r").getBytes());
              out.write(m,0,m.length);
              out.write(("\r").getBytes());
              out.write(("\r").getBytes());
              out.write(("GOALS FOR NEXT QUARTER: ").getBytes());
              out.write(("\r").getBytes());
              byte[] n = jtfGoals.getText().getBytes();
              out.write(n,0,n.length);
              out.close();
            catch(IOException ex)
    [\code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • JFileChooser - FireFox on OS X - showSaveDialog returns immediately or hang

    I have a singed applet that uses the JFileChooser to allow the suer to pick a file location. This works with FF and IE on Windows, works with Safari on OS X and used to work with FF on OS X. However a bug was just discovered where it no longer works with FF on OS X.
    JFileChooser chooser = new JFileChooser();
    // ask the user where we should save the file
    chooser.setCurrentDirectory(new File(System.getProperty("user.home")));
    System.out.println("*************************** "+System.getProperty("user.home"));
    chooser.setSelectedFile(new File(attachmentName));
    chooser.setDialogTitle("Save Attachment - " + attachmentName);
    int returnVal = chooser.showSaveDialog(null);
    System.out.println("*************************** "+returnVal);
    Doing the above I either get a complete hange of the broswer and VM or the showSaveDialog call returns immediately with a value of ERROR_OPTION and then the dialog is displayed.
    It doesn't seems to make a difference where I put the above code.
    We were supposed to do a release of the software today but this is a show stopper. Any help would be great.

    I've now tried the following:
    public void doit() {
    Runnable getTextFieldText = new Runnable() {
    public void run() {
    System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%% 1 "+ SwingUtilities.isEventDispatchThread() );
    JFileChooser chooser = new JFileChooser();
    System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%% 2 "+ SwingUtilities.isEventDispatchThread() );
    chooser.setCurrentDirectory(new File(System.getProperty("user.home")+"/Desktop/"));
    System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%% 3 "+ SwingUtilities.isEventDispatchThread() );
    chooser.setSelectedFile(new File("fred"));
    System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%% 4 "+ SwingUtilities.isEventDispatchThread() );
    chooser.setDialogTitle("Save Attachment - ");
    System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%% 5 "+ SwingUtilities.isEventDispatchThread() );
    int returnVal = chooser.showSaveDialog(null);
    System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@ "+returnVal);
    try{
    SwingUtilities.invokeLater(getTextFieldText);
    }catch(Exception x){
    x.printStackTrace();
    Which works everywhere except FF which hang after the user dismisses the dialog. I'm begging for any insight here.

Maybe you are looking for