Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.awt.BorderLayout;

import java.awt.Dimension;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JDesktopPane;
import javax.swing.JFileChooser;
import javax.swing.JInternalFrame;

public class Main {
    /**
     * Displays a specified <code>JFileChooser</code> in a JInternalFrame. <br />
     * The JInternalFrame will close when the dialog is closed. <br />
     * 
     * @param desktop the JDesktopPane on which to display the JFileChooser
     * @param ch the JFileChooser to display
     */
    public static void showInternalFileChooser(JDesktopPane desktop, final JFileChooser ch) {
        final JInternalFrame frm = new JInternalFrame(ch.getDialogTitle());
        frm.setClosable(true);
        frm.setResizable(true);
        frm.setLayout(new BorderLayout());
        frm.add(ch, BorderLayout.CENTER);
        frm.setVisible(true);

        frm.pack();

        Dimension size = frm.getSize();
        frm.setLocation(desktop.getWidth() / 2 - size.width / 2, desktop.getHeight() / 2 - size.height / 2);
        desktop.add(frm, 0);

        ch.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                frm.dispose();
                ch.removeActionListener(this);
            }
        });

        try {
            frm.setSelected(true);
        } catch (java.beans.PropertyVetoException e) {
        }
    }
}