0

I want to add the some additional functionality to the FileDialog. That is I want to add File Format and Encoding options to the default FileDialog of Swing. How can I add additional functionality?

Here is Default FileDialog code:

public class JFrameDemo extends javax.swing.JFrame {

public JFrameDemo() {
   initComponents();
}

@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">                          
private void initComponents() {

    tabbedPane = new javax.swing.JTabbedPane();
    menuBar = new javax.swing.JMenuBar();
    jMenu3 = new javax.swing.JMenu();
    open = new javax.swing.JMenuItem();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    menuBar.setBackground(new java.awt.Color(51, 51, 255));

    jMenu3.setText("File");

    open.setText("Open");
    open.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            openActionPerformed(evt);
        }
    });
    jMenu3.add(open);

    menuBar.add(jMenu3);

    setJMenuBar(menuBar);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(tabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(tabbedPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 331, Short.MAX_VALUE)
    );

    pack();
}// </editor-fold>                        

private void openActionPerformed(java.awt.event.ActionEvent evt) {                                     
    FileDialog fd = new FileDialog(JFrameDemo.this, "Select File", FileDialog.LOAD);
    fd.show();
}                                    

public static void main(String args[]) {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(JFrameDemo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(JFrameDemo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(JFrameDemo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(JFrameDemo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
           // ImageIcon img = new ImageIcon("C:\\Icons\book-edit-icon.png");
            JFrameDemo fdemo=new JFrameDemo();

            fdemo.setVisible(true);
        }
    });
}
// Variables declaration - do not modify                     
private javax.swing.JMenu jMenu3;
private javax.swing.JMenuBar menuBar;
private javax.swing.JMenuItem open;
private javax.swing.JTabbedPane tabbedPane;
// End of variables declaration                   
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
user3556256
  • 47
  • 3
  • 9
  • See also the [File Browser GUI](http://codereview.stackexchange.com/questions/4446/file-browser-gui). – Andrew Thompson Jul 17 '14 at 07:24
  • 1
    Is there a specific reason you are using the `FileDialog` class ? Sounds to me like you can fulfil all your requirements using a customized `JFileChooser` – Robin Jul 17 '14 at 07:25
  • @robin I want to customize FileDialog class only.Because I had write a code for open a conents of given selected file in JTextPane.So,please help me.Thank you in advance. – user3556256 Jul 17 '14 at 12:20
  • `JTextPane` is already a Swing component. So I repeat, is there a good reason to use the AWT `FileDialog` class instead of the Swing variant `JFileChooser`. You can take a look at the [tutorial](http://docs.oracle.com/javase/tutorial/uiswing/components/filechooser.html) to see the customization options of the `JFileChooser` class – Robin Jul 17 '14 at 15:18
  • @Robin Thank you for reply. The Look and Feel of JFileDialog is good compare to JFileChooser.That's why I keep JFilDialog and I want to customize it.Please help me – user3556256 Jul 18 '14 at 05:39

0 Answers0