JFileChooser as a Panel

hi..
i m trying to make an application where the user has the option of opening a file from JFileCHooser or choosing a file from a recent file list in a (say) listbox... and these two options r in tabbed panes........
so how can i get a panel from JFileChooser so that i can attach it to the tabbed pane..
regards
ankur

JFileChooser is a JComponent:
import javax.swing.*;
public class Example {
    public static void main(String[] args) {
        JTabbedPane tabbedPane = new JTabbedPane();
        tabbedPane.addTab("choose file", new JFileChooser());
        tabbedPane.addTab("choose color", new JColorChooser());
        final JFrame f = new JFrame("Example");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(tabbedPane);
        f.pack();
        SwingUtilities.invokeLater(new Runnable(){
            public void run() {
                f.setLocationRelativeTo(null);
                f.setVisible(true);
}

Similar Messages

  • JFileChooser as a panel, not as a dialog

    I'm trying to use a JFileChooser as a panel in a wizard.
    I can get the selected file name back if the user double-clicks by adding an ActionListener onto the chooser.
    I can get the selected file name back if the user single-clicks by adding a PropertyChangeListener (prop = SelectedFileChangedProperty).
    However, if the user enters a name by typing it (or pasting it I guess), when I call getSelectedFile(), it returns the wrong value.
    So, I need to know how to read the value that's in the text field, or get an event when the user changes it, or make the field un-editable.
    I've searched the forums for quite a while, but have not found any applicable topics. Can this be done? Thanks...

    I was able to get the value from that text by extending JFileChooser, and adding this recursive method:
       public String getEnteredFile (Component c)
          if (c instanceof JTextField)
             return ((JTextField) c).getText();
          if (c instanceof Container)
             for (Component child : ((Container) c).getComponents())
                String text = getEnteredFile (child);
                if (text != null)
                   return text;
          return null;
    However, I still can't tell if the user has entered data into that field, so that I can enable my wizard's Next button. I guess I can use a similar recursive method to get the JTextField, and add a listener on it. Seems kind of clunky, but it should work...

  • Embedding a JFileChooser in a Panel

    is it possible to embed a file chooser in a JPanel?, i'm trying to get my program to look something like how CuteHTML does. Or should i just use a JTree to display the dirrectory, and contents?

    Yes, you can embed JFileChooser in a JPanel, since JFileChooser is merely a subclass of JComponent. Use the JPanel's add(Component c) method (inherited from java.awt.Container)...
    I don't know, however, what CuteHTML looks like. If you can get away with using the JFileChooser, do so, as it will save you ALOT of work having to rig a TreeModel, etc., for use with a JTree.
    good luck.

  • JFileChooser as a JComponent

    I've added a JFileChooser to a panel and disabled the standard control buttons (as they would conflict with the general feel of my application, which has a "next" button elsewhere). I want to be notified when the user selects a file and I have attached a PropertyChangeListener accordingly. I have but one problem.
    If I simply type a filename into the text field, no change event is fired. I must press the enter key in the text field for the change to take effect. It seems that what I need is a way to actively request that the JFileChooser update its selected file based on the contents of the filename text field. How might I do this?
    (The only solution I have so far is something like:
    JFileChooser chooser = ...;
    ((BasicFileChooserUI)(chooser.getUI())).getApproveSelectionAction().actionPerformed(new ActionEvent(...));which is ugly on so many levels...)

    I've added a JFileChooser to a panel and disabled the standard control buttons (as they would conflict with the general feel of my application, which has a "next" button elsewhere). I want to be notified when the user selects a file and I have attached a PropertyChangeListener accordingly. I have but one problem.
    If I simply type a filename into the text field, no change event is fired. I must press the enter key in the text field for the change to take effect. It seems that what I need is a way to actively request that the JFileChooser update its selected file based on the contents of the filename text field. How might I do this?
    (The only solution I have so far is something like:
    JFileChooser chooser = ...;
    ((BasicFileChooserUI)(chooser.getUI())).getApproveSelectionAction().actionPerformed(new ActionEvent(...));which is ugly on so many levels...)

  • JFileChooser functioning like normal Windows Apps FileChooser

    I have this problem that's been giving me too much headache already. When you click on Open on any Windows app, and click on the "Details" button, it will show you the files' details (FileName, Type, Date, etc.). This is the same with JFileChooser, so no problem there. The thing is, with Windows apps, you can click on the headers and have the files sorted according to the header you clicked. This doesn't happen to a JFileChooser. Has any of you guys did this or found any solution to this problem? I've searched (almost) everywhere, Google, Sun, etc., I even looked into JFileChooser's source code but I can't seem to find anything.
    I know this is possible, so anyone who can help, you'll be greatly appreciated.

    Thought I would pass along some updated code for this as this was very helpful to us as we are still on jdk 1.5.
    This has been modified to use the Windows UI. The advantage of doing this in the UI class is so you can set it as the default UI for JFileChooser inside your application. If you had this as a subclass of JFileChooser (as it is above) then you explicitly have to use that subclass throughout your application. By setting this UI class as the FileChooserUI in your UIDefaults table then every instance of JFileChooser will now automatically use your overridden UI and theres nothing else you have to do.
    import java.awt.Component;
    import java.awt.Container;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.io.File;
    import java.util.Collections;
    import java.util.Comparator;
    import java.util.Vector;
    import javax.swing.JComponent;
    import javax.swing.JFileChooser;
    import javax.swing.JPanel;
    import javax.swing.JTable;
    import javax.swing.UIManager;
    import javax.swing.plaf.ComponentUI;
    import javax.swing.plaf.basic.BasicDirectoryModel;
    import javax.swing.table.JTableHeader;
    import javax.swing.table.TableColumn;
    import javax.swing.table.TableColumnModel;
    import com.sun.java.swing.plaf.windows.WindowsFileChooserUI;
    public class SortableFileChooserUI extends WindowsFileChooserUI {
         private DirectoryModel model;
         public static ComponentUI createUI(JComponent c) {
              return new SortableFileChooserUI((JFileChooser)c);
         public SortableFileChooserUI(JFileChooser filechooser) {
              super(filechooser);
         @Override
      protected final void createModel() {
              this.model = new DirectoryModel(getFileChooser());
          * Overridden to get our own model
          * @return
         @Override
      public final BasicDirectoryModel getModel() {
              return this.model;
          * Calls the default method then adds a MouseListener to the JTable
          * @param chooser
          * @return
         @Override
      protected final JPanel createDetailsView(JFileChooser chooser) {
              JPanel panel = super.createDetailsView(chooser);
              //Since we can't access FileChooserUI's private member detailsTable
              //directly, we have to find it in the JPanel
              final JTable tbl = findJTable(panel.getComponents());
              if (tbl != null) {
                   //Fix the columns so they can't be rearranged, if we don't do this
                   //we would need to keep track when each column is moved
                   tbl.getTableHeader().setReorderingAllowed(false);
                   //Add a mouselistener to listen for clicks on column headers
                   tbl.getTableHeader().addMouseListener(new MouseAdapter() {
                        @Override
            public void mouseClicked(MouseEvent e) {
                             //Only process single clicks
                             if (e.getClickCount() > 1) {
                return;
                             e.consume();
                             Column column = Column.getColumn(tbl.getTableHeader().columnAtPoint(e.getPoint()));
                             if ((column != null) && column.isSortable()) {
                SortableFileChooserUI.this.model.sort(tbl.getTableHeader().columnAtPoint(e.getPoint()), tbl);
              return panel;
          * Finds the JTable in the panel so we can add MouseListener
          * @param comp
          * @return
         private final JTable findJTable(Component[] comp) {
              for (int i = 0; i < comp.length; i++) {
                   if (comp[i] instanceof JTable) {
                        return (JTable)comp;
                   if (comp[i] instanceof Container) {
                        JTable tbl = findJTable(((Container)comp[i]).getComponents());
                        if (tbl != null) {
    return tbl;
              return null;
         private final static class DirectoryModel extends BasicDirectoryModel {
              private Column col = Column.FILENAME;
              private boolean ascending;
              private Comparator<File> filesizeComparator = new FilesizeComparator();
              private Comparator<File> filenameComparator = new FilenameComparator();
              private Comparator<File> filedateComparator = new FiledateComparator();
              * Must be overridden to extend BasicDirectoryModel
              * @param chooser
              protected DirectoryModel(JFileChooser chooser) {
                   super(chooser);
              * Resorts the JFileChooser table based on new column
              * @param c
              protected final void sort(int c, JTable tbl) {
                   //Set column and order
                   this.col = Column.getColumn(c);
                   this.ascending = !this.ascending;
                   String indicator = " ^";
                   if (this.ascending) {
                        indicator = " v";
                   final JTableHeader th = tbl.getTableHeader();
                   final TableColumnModel tcm = th.getColumnModel();
                   for (Column column : Column.values()) {
                        tcm.getColumn(column.getIndex()).setHeaderValue(column.getLabel());
                   final TableColumn tc = tcm.getColumn(this.col.getIndex()); // the column to change
                   tc.setHeaderValue(this.col.getLabel() + indicator);
                   th.repaint();
                   //Requery the file listing
                   validateFileCache();
              * Sorts the data based on current column setting
              * @param data
              @Override
    protected final void sort(Vector<? extends File> data) {
                   Comparator<File> comparator = null;
                   switch (this.col) {
                        case FILEDATE:
                             comparator = this.filedateComparator;
                             break;
                        case FILESIZE:
                             comparator = this.filesizeComparator;
                             break;
                        case FILENAME:
                             comparator = this.filenameComparator;
                             break;
                        default:
                             comparator = null;
                             break;
                   if (comparator != null) {
                        Collections.sort(data, comparator);
              private class FiledateComparator implements Comparator<File> {
                   public int compare(File a, File b) {
                        int ret = 1;
                        if (a.lastModified() > b.lastModified()) {
                             ret = -1;
                        else if (a.lastModified() == b.lastModified()) {
                             ret = 0;
                        if (DirectoryModel.this.ascending) {
                             ret *= -1;
                        return ret;
              private class FilesizeComparator implements Comparator<File> {
                   public int compare(File a, File b) {
                        int ret = 1;
                        if (a.length() > b.length()) {
                             ret = -1;
                        else if (a.length() == b.length()) {
                             ret = 0;
                        if (DirectoryModel.this.ascending) {
                             ret *= -1;
                        return ret;
              private class FilenameComparator implements Comparator<File> {
                   public int compare(File a, File b) {
                        if (DirectoryModel.this.ascending) {
                             return a.getName().compareToIgnoreCase(b.getName());
                        else {
                             return -1 * a.getName().compareToIgnoreCase(b.getName());
         private enum Column {
              FILENAME(0, UIManager.getString("FileChooser.fileNameHeaderText"), true),
              FILESIZE(1, UIManager.getString("FileChooser.fileSizeHeaderText"), true),
              FILETYPE(2, UIManager.getString("FileChooser.fileTypeHeaderText")),
              FILEDATE(3, UIManager.getString("FileChooser.fileDateHeaderText"), true),
              FILEATTR(4, UIManager.getString("FileChooser.fileAttrHeaderText"));
              private int index;
              private String label;
              private boolean isSortable;
              private Column(int index, String label) {
                   this(index, label, false);
              private Column(int index, String label, boolean isSortable) {
                   this.index = index;
                   this.label = label;
                   this.isSortable = isSortable;
              protected int getIndex() { return this.index; }
              protected String getLabel() { return this.label; }
              protected boolean isSortable() { return this.isSortable; }
              @Override public String toString() { return getLabel(); }
              protected static Column getColumn(int index) {
                   for (Column column : values()) {
                        if (column.getIndex() == index) {
                             return column;
                   return null;

  • Transparent JFileChooser

    Hi!
    I have yet another "how can I make this thing transparent" question, this time for the JFileChooser. I've written a function to recursively iterate through its components and these are the ones I can find:
    class javax.swing.JPanel
    class javax.swing.JPanel
    class javax.swing.JButton
    class javax.swing.Box$Filler
    class javax.swing.JButton
    class javax.swing.Box$Filler
    class javax.swing.JButton
    class javax.swing.Box$Filler
    class javax.swing.JToggleButton
    class javax.swing.JToggleButton
    class javax.swing.JLabel
    class javax.swing.plaf.metal.MetalFileChooserUI$1
    class javax.swing.JPanel
    class sun.swing.FilePane
    class javax.swing.JPanel
    class javax.swing.JPanel
    class javax.swing.plaf.metal.MetalFileChooserUI$AlignedLabel
    class javax.swing.plaf.metal.MetalFileChooserUI$3
    class javax.swing.Box$Filler
    class javax.swing.JPanel
    class javax.swing.plaf.metal.MetalFileChooserUI$AlignedLabel
    class javax.swing.JComboBox
    class javax.swing.JPanel
    class javax.swing.JButton
    class javax.swing.JButtonRunning setOpaque(false) on all instances of JComponent makes everything but the list of files transparent. From what I can see it's some kind of JList but it doesn't appear in the list above. Is there a way to make this last part transparent as well? Can I somehow run setOpaque(false) on it too?

    Thanks for your replies!
    I realise now I probably should have put some more effort into this before posting. I've created an example that'll hopefully make things clearer.
    Maxideon: You're right, ComboBox doesn't become transparent, it did in my code because I'd set a custom ComboBoxUI.
    It's only the list of files I'm interested in making transparent right now, I've managed to get all of the other components transparent already. Here's the code:
    FileChooserTest.java:
    import java.awt.*;
    import javax.swing.*;
    public class FileChooserTest extends JFrame {
      String background = "bkg.jpg";
      public FileChooserTest() {
        ImageIcon imageIcon = new ImageIcon(background);
        setSize(imageIcon.getIconWidth(), imageIcon.getIconHeight());
        JPanel panel = new JPanel() {
          public void paintComponent(Graphics g) {
            g.drawImage(new ImageIcon(background).getImage(), 0, 0, null);
        panel.setBounds(0, 0, imageIcon.getIconWidth(), imageIcon.getIconHeight());
        UIManager.put("FileChooserUI", MyFileChooserUI.class.getName());
        panel.add(new JFileChooser());
        getContentPane().add(panel);
      public static void main(String[] args) {
        new FileChooserTest().setVisible(true);
    }MyFileChooserUI.java
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.plaf.ComponentUI;
    import javax.swing.plaf.metal.MetalFileChooserUI;
    public class MyFileChooserUI extends MetalFileChooserUI {
      public static ComponentUI createUI(JComponent c) {
        return new MyFileChooserUI((JFileChooser) c);
      private MyFileChooserUI(JFileChooser c) {
        super(c);
      public void installComponents(JFileChooser fc) {
        super.installComponents(fc);
        customize(fc);
      /* Set opacity, call recursively */
      private void customize(Container c) {
        int len = c.getComponentCount();
        for(int i = 0; i < len; i++) {
          Component comp = c.getComponent(i);
          if(comp instanceof JComponent) {
            ((JComponent)comp).setOpaque(false);
          if(comp instanceof Container) {
            customize((Container) comp);
    }thomas.behr: Does your solution work for a JFileChooser added to a JPanel or only when it's a separate Window?
    Is there a way to create a custom ListUI that'll make the list in the JFileChooser transparent?
    Once again, thanks guys and sorry for not creating an example from the start.

  • Creating a JAR executable

    I made a simple calculator in java and I want to zip it up in an excutable jar file. I have 3 classes including my main in my .java file and am having trouble creating the jar archive. The source code for this program is:
    import java.awt.*;
    import java.awt.event.*;
    import java.io.File;
    import javax.swing.*;
    // Frame for button panel
    class CalculatorFrame extends JFrame
         public CalculatorFrame()
              Toolkit kit = Toolkit.getDefaultToolkit();
              // sets title & icon image for window
              setTitle("Java Calculator v1.0 by D. Burkland");
              Image img = kit.getImage("calc.gif");
              setIconImage(img);     
              // add panel to frame
              CalculatorPanel calculator = new CalculatorPanel();
              add(calculator);
              pack();
              // centers frame
              Dimension screenSize = kit.getScreenSize();
              int screenHeight = screenSize.height;
              int screenWidth = screenSize.width;
              // center & set dimensions of frame
              setSize(width, height);
              setLocation(screenWidth / 3, screenHeight / 3);
              // set file chooser
              chooser = new JFileChooser();
              chooser.setCurrentDirectory(new File("."));
              // set up menu bar
              JMenuBar menuBar = new JMenuBar();
              setJMenuBar(menuBar);
              JMenu filemenu = new JMenu("File");
              JMenu helpmenu = new JMenu("Help");
              menuBar.add(filemenu);
              menuBar.add(helpmenu);
              // action of the exit text
              JMenuItem exitItem = new JMenuItem("Exit");
              filemenu.add(exitItem);
              exitItem.addActionListener(new
                        ActionListener()
                             public void actionPerformed(ActionEvent event)
                                  System.exit(0);
              JMenuItem helpItem = new JMenuItem("About");
              helpmenu.add(helpItem);
              helpItem.addActionListener(new
                        ActionListener()
                             public void actionPerformed(ActionEvent event)
                                  JOptionPane.showMessageDialog(null, "Java Calculator By: D. Burkland Summer 2006");               
         public static final int width = 350;
         public static final int height = 200;
         private JFileChooser chooser;
    // Calculator panel
    class CalculatorPanel extends JPanel
         public CalculatorPanel()
              setLayout(new BorderLayout());
              result = 0;
              lastCommand = "=";
              start = true;
              // add the display
              display = new JButton("Hello");
              display.setEnabled(false);
              add(display, BorderLayout.NORTH);
              ActionListener insert = new InsertAction();
              ActionListener command = new CommandAction();
              // adds the buttons in a 4 x 4 grid
              calculator = new JPanel();
              calculator.setLayout(new GridLayout(4, 4));
              addButton("7", insert);
              addButton("8", insert);
              addButton("9", insert);
              addButton("/", command);
              addButton("4", insert);
              addButton("5", insert);
              addButton("6", insert);
              addButton("*", command);
              addButton("1", insert);
              addButton("2", insert);
              addButton("3", insert);
              addButton("-", command);
              addButton("0", insert);
              addButton(".", insert);
              addButton("=", command);
              addButton("+", command);
              add(calculator, BorderLayout.CENTER);
         Adds a button to the center panel
         @param lable the button label
         @param listener the button listener
         private void addButton(String label, ActionListener listener)
              JButton button = new JButton(label);
              button.addActionListener(listener);
              calculator.add(button);
         // Inserts the button action string to the end of the display
         private class InsertAction implements ActionListener
              public void actionPerformed(ActionEvent event)
                   String input = event.getActionCommand();
                   if (start)
                        display.setText("");
                        start = false;
                   display.setText(display.getText() + input);
         // Executes the command that the button action string demotes
         private class CommandAction implements ActionListener
              public void actionPerformed(ActionEvent event)
                   String command = event.getActionCommand();
                   if (start)
                        if (command.equals("-"))
                             display.setText(command);
                             start = false;
                        else
                             lastCommand = command;
                   else
                        calculate(Double.parseDouble(display.getText()));
                        lastCommand = command;
                        start = true;
         // Carries out the pending calculation
         public void calculate(double x)
              if (lastCommand.equals("+")) result += x;
              else if (lastCommand.equals("-")) result -= x;
              else if (lastCommand.equals("*")) result *= x;
              else if (lastCommand.equals("/")) result /= x;
              else if (lastCommand.equals("=")) result = x;
              display.setText("" + result);
         private JButton display;
         private JPanel calculator;
         private double result;
         private String lastCommand;
         private boolean start;
    public class Calculator
         public static void main(String[] args)
              CalculatorFrame calculator = new CalculatorFrame();
              calculator.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              calculator.setVisible(true);
    }I am using Eclipse to create the jar files so if anybody has any advice I would be very grateful if you shared it.
    Thanks,
    Danny

    Well I keep getting errors so I am doing something wrong. The errors I get are:
    java.io.FileNotFoundException: jarexample.jar (The system cannot find the file specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:
    106)
    java.io.FileInputStream.<init>(FileInputStream.java:66)
    at sun.tools.jar.Main.run(Main.java:122)
    at sun.tools.jar.Main.main(Main.java:903)So I have 3 classes, but after compiling the program I have many .class files: Calculator.class, CalculatorFrame$1.class, CalculatorFrame$2.class, CalculatorFrame.class, CalculatorPanel$CommandAction.class, CalculatorPanel$InsertAction.class, and CalculatorPanel.class. Which files do I want to export into my jar file and do I have to open these class files in Eclipse? Also could you explain the manifest thing first, I have googled for this stuff but get confused because of the class file issue that I previously stated.
    Thanks again for helping a noobie out :)
    Message was edited by:
    danny9894
    Message was edited by:
    danny9894

  • Parent directory on JFileChooser main panel

    Yes I did a search on the forum before posting.
    How could I display the parent directory '..' of the current directory on the file list panel of a JFileChooser? It should be selectable/clickable/openable, of course.

    Thanks camickr.
    It does barely works but problems are:
    1) A mouse selection on the parent directory [icon + text] item behaves weird at the initial launch time of the program and when we have returned back from a subsub-directory.
    2)The parent directory [icon + text] item doesn't come at the top of the file list. How to achieve this requirement?
    Here's a quick and dirty SSCCE:
    import javax.swing.*;
    import javax.swing.filechooser.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.beans.*;
    import java.io.*;
    import java.net.*;
    public class ParentFcTest{
      JFrame frame;
      JFileChooser jfc;
      JPanel contentPane, mainPanel;
      Box buttonPanel;
      JButton convButton, rescanButton;
      boolean inProgress;
      File cf; // file currently processed
      FsvWithParentDir fwp;
      FvForPd ffp;
      public ParentFcTest(){
        frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jfc = new JFileChooser(".", fwp = new FsvWithParentDir());
        jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        Component comp = jfc.getComponent(3);
        comp.setVisible(false); // hide labels, textfields, buttons etc.
        ffp = new FvForPd(fwp);
        jfc.setFileView(ffp);
        mainPanel = new JPanel(new BorderLayout());
        mainPanel.add(jfc, BorderLayout.CENTER);
        convButton = new JButton("...Select file or folder");
        buttonPanel = new Box(BoxLayout.Y_AXIS);
        JPanel p1 = new JPanel();
        p1.add(convButton);
        rescanButton = new JButton("Update file list");
        rescanButton.setBackground(new Color(200, 255, 50));
        JPanel p2 = new JPanel();
        p2.add(rescanButton);
        buttonPanel.add(p1);
        buttonPanel.add(p2);
        rescanButton.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent e){
            jfc.rescanCurrentDirectory();
        contentPane = (JPanel)frame.getContentPane();
        contentPane.add(mainPanel, BorderLayout.CENTER);
        contentPane.add(buttonPanel, BorderLayout.SOUTH);
        frame.pack();
        frame.setVisible(true);
        jfc.addPropertyChangeListener(new PropertyChangeListener(){
          File f;
          public void propertyChange(PropertyChangeEvent pce){
            f = jfc.getSelectedFile();
            if (f == cf){ // we need this because of #$# below
              return;
            if (inProgress){ // vv restore old selection
              jfc.setSelectedFile(cf); // #$# generates another PCE !
              JOptionPane.showMessageDialog
           (frame, "Can't select a new file while processing current file");
              return;
            if (pce.getPropertyName().equals
             (JFileChooser.SELECTED_FILE_CHANGED_PROPERTY)){ // selected
              if (f.isFile()){
                convButton.setText("Process this file");
              else if (f.isDirectory()){
                convButton.setText("Open this folder");
            else if (pce.getPropertyName().equals
             (JFileChooser.DIRECTORY_CHANGED_PROPERTY)){ // physical dir change
              convButton.setText("...Select file or folder");
        convButton.addActionListener(new Converter(jfc));
      } // constructor
      class Converter implements ActionListener{
        JFileChooser fc;
        public Converter(JFileChooser jf){
          fc = jf;
        public void actionPerformed(ActionEvent e){
          JButton btn = (JButton)e.getSource();
          if (btn.getText().startsWith("...")){ // message only, no action
            return;
          File f = fc.getSelectedFile();
          if (f.isFile()){
            inProgress = true;
            rescanButton.setEnabled(false);
            cf = f;
            convButton.setText("...please wait");
            ConvWorker cw = new ConvWorker();
            cw.execute();
          else{
            jfc.setCurrentDirectory(f);
      class ConvWorker extends SwingWorker<Object,Object>{
        public Object doInBackground(){
          return null;
        protected void done(){
          inProgress = false;
          jfc.rescanCurrentDirectory();
          convButton.setText("...Select file or folder");
          rescanButton.setEnabled(true);
      class FvForPd extends FileView{
        FsvWithParentDir fsvp;
        ImageIcon ii;
        public FvForPd(FsvWithParentDir fsv){
          fsvp = fsv;
          try{
            ii = new ImageIcon
              (new URL("http://homepage1.nifty.com/algafield/pardir.gif"));
          catch (MalformedURLException e){
            e.printStackTrace();
        public Icon getIcon(File f){
          if (f.equals(fsvp.getParent())){
            return ii;
          else{
            return super.getIcon(f);
        public String getName(File f){ // it does work but...
          if (f.equals(fsvp.getParent())){
            return ("..");
          else{
            return super.getName(f);
      public static void main(String[] args){
        SwingUtilities.invokeLater(new Runnable(){
          public void run(){
            new ParentFcTest();
    import java.io.*;
    import javax.swing.*;
    import javax.swing.filechooser.*;
    public class FsvWithParentDir extends FileSystemView{
      File[] filelist;
      File parent;
      public File createNewFolder(File containingDir){
        File folder = new File(containingDir, "NEWFOLDER");
        folder.mkdir();
        return folder;
      public File[] getFiles(File dir, boolean useFileHiding){
        File[] files = super.getFiles(dir, useFileHiding);
        File[] nfiles = new File[files.length + 1];
        for (int i = 1; i < nfiles.length; ++i){
          nfiles[i] = files[i - 1];
        parent = dir.getParentFile();
        if (parent != null){
          nfiles[0] = parent;
          filelist = nfiles;
        else{
          filelist = files;
        return filelist;
      public File getParent(){
        return parent;
      // this doesn't work
      public Icon getSystemIcon(File f){
        if (parent != null && f.equals(parent)){
          ImageIcon ii = new ImageIcon(getClass().getResource("/pardir.gif"));
          return ii;
        else{
          return super.getSystemIcon(f);
    }

  • Saving parameters entered in a gui dialog to be used in the main panel

    Hi,
    I'm having a nightmare at the moment.
    I've finished creating a program for my final year project, that is all comand line at the moment.
    i'm required to design a GUI for this. i've started already and have a main panel that has a few buttons one of which is a setParameters button. which opens up a file dialog that allows the user to enter parameters that will be used by the main panel later on.
    I'm having trouble imagining how these parameters will be accessed by the main Panel once they are saved.
    At the moment, without the GUI i have get and set methods in my main program which works fine. Is this the kind of thing i'll be using for this?
    my code for the parameters dialog
    public class Parameters  extends JDialog
         private GridLayout grid1, grid2, grid3;
         JButton ok, cancel;
            public Parameters()
                    setTitle( "Parameters" );
                    setSize( 400,500 );
                    setDefaultCloseOperation( DISPOSE_ON_CLOSE );
              grid1 = new GridLayout(7,2);
              grid2 = new GridLayout(1,2);
                    JPanel topPanel = new JPanel();
                    topPanel.setLayout(grid1);
              JPanel buttonPanel = new JPanel();
                    buttonPanel.setLayout(grid2);
              ok = new JButton("OK");
                  ok.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                  //when pressed i want to save the parameters that the user has entered
              //and be able to access these in the RunPanel class
              cancel = new JButton("Cancel");
                 cancel.addActionListener(new ActionListener() {
                          public void actionPerformed(ActionEvent e) {
                        //when pressed just want the Jdialog  to close
              buttonPanel.add(ok);
              buttonPanel.add(cancel);
              JTextArea affinityThresholdScalar = new JTextArea();
              JTextArea clonalRate = new JTextArea();
              JTextArea stimulationValue = new JTextArea();
              JTextArea totalResources = new JTextArea();
              JLabel aTSLabel = new JLabel("affinityThresholdScalar");
              JLabel cRLabel = new JLabel("clonalRate");
              topPanel.add(aTSLabel);
              topPanel.add(affinityThresholdScalar);
              topPanel.add(cRLabel);
              topPanel.add(clonalRate);
                    Container container = getContentPane();//.add( topPanel );
              container.add( topPanel, BorderLayout.CENTER );
              container.add( buttonPanel, BorderLayout.SOUTH );
         }the main panel class is:
    public class RunPanel extends JPanel implements ActionListener
         JButton openButton, setParametersButton, saveButton;
         static private final String newline = "\n";
         JTextArea log;
             JFileChooser fc;
         Data d = new Data();
         Normalise rf = new Normalise();
         Parameters param = new Parameters();
        public RunPanel()
            super(new BorderLayout());
            log = new JTextArea(5,20);
            log.setMargin(new Insets(5,5,5,5));
            log.setEditable(false);
            JScrollPane logScrollPane = new JScrollPane(log);
            fc = new JFileChooser();
            openButton = new JButton("Open a File...")
            openButton.addActionListener(this);
         setParametersButton = new JButton("Set User Parameters");
            setParametersButton.addActionListener(this);
         saveButton = new JButton("save");
            saveButton.addActionListener(this);
            JPanel buttonPanel = new JPanel(); //use FlowLayout
            buttonPanel.add(openButton);
         buttonPanel.add(setParametersButton);
         JPanel savePanel = new JPanel();
         savePanel.add(saveButton);
            add(buttonPanel, BorderLayout.PAGE_START);
            add(logScrollPane, BorderLayout.CENTER);
         add(savePanel, BorderLayout.SOUTH);
        public void actionPerformed(ActionEvent e) {
            if (e.getSource() == openButton) {
                int returnVal = fc.showOpenDialog(RunPanel.this);
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    File file = fc.getSelectedFile();
                    log.append("Opening: " + file.getName() + "." + newline);
              Vector data = d.readFile(file);
              log.append("Reading file into Vector " +data+ "." + newline);
              Vector dataNormalised = rf.normalise(data);
             else {
                    log.append("Open command cancelled by user." + newline);
                log.setCaretPosition(log.getDocument().getLength());
         else if (e.getSource() == saveButton) {
                int returnVal = fc.showSaveDialog(RunPanel.this);
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    File file = fc.getSelectedFile();
                    log.append("Saving: " + file.getName() + "." + newline);
                } else {
                    log.append("Save command cancelled by user." + newline);
                log.setCaretPosition(log.getDocument().getLength());
         else
              if (e.getSource() == setParametersButton)
                    log.append("loser." + newline);
                          param.show();
        private static void createAndShowGUI() {
            JFrame.setDefaultLookAndFeelDecorated(true);
            JDialog.setDefaultLookAndFeelDecorated(true);
            JFrame frame = new JFrame("AIRS");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JComponent newContentPane = new RunPanel();
            newContentPane.setOpaque(true);
            frame.setContentPane(newContentPane);
            frame.pack();
            frame.setVisible(true);
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
    }Can anybody offer any suggestions?
    Cheers

    What you need is my ParamDialog. I think it could be perfect for this sort of thing. There are a few references in it to some of my other classes namely
    StandardDialog. Which you can find by searching for other posts on this forum. But if you'd rather not find that you could just use JDialog instead
    WindowUtils.visualize() this is just a helper method for getting things visualized on the screen. You can just use setBounds and setVisible and you'll be fine.
    You are welcome to use and modify this code but please don't change the package or take credit for it as your own work.
    If you need to bring up a filedialog or a color chooser you will need to make some modifications. If you do this, would you mind posting that when you are done so that myself and others can use it? :)
    StandardDialog.java
    ================
    package tjacobs.ui;
    import java.awt.Dialog;
    import java.awt.Frame;
    import java.awt.GraphicsConfiguration;
    import java.awt.HeadlessException;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JPasswordField;
    import javax.swing.JTextField;
    import java.awt.*;
    import java.util.HashMap;
    import java.util.Properties;
    /** Usage:
    * *      ParamDialog pd = new ParamDialog(new String[] {"A", "B", "C"});
    * pd.pack();
    * pd.setVisible(true);
    * Properties p = pd.getProperties();
    public class ParamDialog extends StandardDialog {
         public static final String SECRET = "(SECRET)";
         String[] fields;
         HashMap<String, JTextField> mValues = new HashMap<String, JTextField>();
         public ParamDialog(String[] fields) throws HeadlessException {
              this(null, fields);
         public ParamDialog(JFrame owner, String[] fields) {
              super(owner);
              setModal(true);
              this.fields = fields;
              JPanel main = new JPanel();
              main.setLayout(new GridLayout(fields.length, 1));
              for (int i = 0; i < fields.length; i++) {
                   JPanel con = new JPanel(new FlowLayout());
                   main.add(con);
                   JTextField tf;
                   if (fields.endsWith(SECRET)) {
                        con.add(new JLabel(fields[i].substring(0, fields[i].length() - SECRET.length())));
                        tf = new JPasswordField();
                   else {
                        con.add(new JLabel(fields[i]));
                        tf = new JTextField();
                   tf.setColumns(12);
                   con.add(tf);
                   mValues.put(fields[i], tf);
              this.setMainContent(main);
         public boolean showApplyButton() {
              return false;
         public void apply() {
         private boolean mCancel = false;
         public void cancel() {
              mCancel = true;
              super.cancel();
         public Properties getProperties() {
              if (mCancel) return null;
              Properties p = new Properties();
              for (int i = 0; i < fields.length; i++) {
                   p.put(fields[i], mValues.get(fields[i]).getText());
              return p;
         public static void main (String[] args) {
              ParamDialog pd = new ParamDialog(new String[] {"A", "B", "C"});
              WindowUtilities.visualize(pd);     
         public static Properties getProperties(String[] fields) {
              ParamDialog pd = new ParamDialog(fields);
              WindowUtilities.visualize(pd);
              return pd.getProperties();          

  • How can I set a default file for JFileChooser

    Hi. I am developing a p2p chat application and I have to unrelated questions.
    1. How can I set a default file name for JFileChooser, to save a completly new file?
    2. I have a JTextArea that I append recieved messages. But when a message is appended, the whole desktop screen refreshes. How can I prevent that?
    Hope I was clear. Thanks in advance.

    Thank you for the first answer, it solved my problem. Here is the code for 2nd question, I've trimmed it a lot, hope I didn't cut off any critical code
    public class ConversationWindow extends JFrame implements KeyListener,MessageArrivedListener,ActionListener,IOnlineUsrComp{
         private TextArea incomingArea;
         private Conversation conversation;
         private JTextField outgoingField;
         private JScrollPane incomingTextScroller;
         private String userName;
         private JButton inviteButton;
         private JButton sendFileButton;
         private JFileChooser fileChooser;
         private FontMetrics fontMetrics;
         private HashMap<String, String> onlineUserMap;
         public void MessageArrived(MessageArrivedEvent e) {
              showMessage(e.getArrivedMessage());
         public ConversationWindow(Conversation conversation)
              this.conversation=conversation;
              userName=User.getInstance().getUserName();
              sendFileButton=new JButton("Dosya G�nder");
              sendFileButton.addActionListener(this);
              inviteButton=new JButton("Davet et");
              inviteButton.addActionListener(this);
              incomingArea=new TextArea();
              incomingArea.setEditable(false);
              incomingArea.setFont(new Font("Verdana",Font.PLAIN,12));
              fontMetrics =incomingArea.getFontMetrics(incomingArea.getFont());
              incomingArea.setPreferredSize(new Dimension(300,300));
              outgoingField=new JTextField();
              outgoingField.addKeyListener(this);
              incomingTextScroller=new JScrollPane(incomingArea);          
              JPanel panel=new JPanel();
              panel.setLayout(new BoxLayout(panel,BoxLayout.PAGE_AXIS));
              panel.add(inviteButton);
              panel.add(sendFileButton);
              panel.add(incomingTextScroller);
              panel.add(outgoingField);
              add(panel);
              pack();
              setTitle("Ki&#351;iler:");
              setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              setLocationRelativeTo(null);
              addWindowListener(new CloseAdapter());
         //Sends the message to other end
         public void keyPressed(KeyEvent e) {
              if(e.getKeyCode()==KeyEvent.VK_ENTER && e.getSource()==outgoingField)
                   String message=outgoingField.getText();
                   if(message.equals("")) return;
                   showMessage(userName+": "+message);
                   conversation.sendMessages(userName+": "+message);
                   outgoingField.setText("");     
         //Displays the recieved message
         public void showMessage(String message)
              if(fontMetrics.stringWidth(message)>incomingArea.getWidth())
                   int mid=message.length()/2;
                   StringBuilder sbld=new StringBuilder(message);
                   for(;mid<message.length();mid++)
                        if(message.charAt(mid)==' ')
                             sbld.setCharAt(mid, '\n');
                             message=sbld.toString();
                             break;
              incomingArea.append("\n"+message);
    }

  • JFileChooser Swatch palette

    i wanted to create a custom dialog, that contains a color (swatch) palette
    i don't want to create one from scatch (*shrugs*). I was able to get the Swatch panel from the JFileChooser
    The problem i'm having now is..when the user click on the color..i want to detect that event and my dialog would get the selected color and process it. Unfortunately, I don't know how to do this. The AbstractColorChooserPanel
    is not really a GUI components like JButton, JTExtFields..etc...so there's no listener to add. I did noticed that i can get the ColorSelectionModel..and throough the colorSelectionModel...i can add a ChangeListener. What i'm afraid of is if i add a new change listener..it would remove the old one..and make the compoennt useless.
    anyone know how i can get the event of a useer selected a color?
    here's how i got the color palette:
    private AbstractColorChooserPanel getColorPalette(int type){
        JColorChooser chooser = new JColorChooser();
        String name = "javax.swing.colorchooser.Default";
        switch (type){
            case SWATCH:  name += "SwatchChooserPanel";         break;
            case HSB:     name += "DefaultHSBChooserPanel";     break;
            case RGB:     name += "DefaultRGBChooserPanel";     break;
            default:      name += "DefaultSwatchChooserPanel";  break;
        AbstractColorChooserPanel[] panels = chooser.getChooserPanels();
        for (int i=0; i < panels.length; i++) {
            String clsName = panels.getClass().getName();
    if (clsName.equals(name))
    return panels[i];
    return null;     

    nevermind. i tested adding a new ChangeListener..and it doesn't remove the old one..which is good and get it to do what i wanted.
    final ColorSelectionModel model = palette.getColorSelectionModel();
    model.addChangeListener(new ChangeListener(){
        public void stateChanged(ChangeEvent e){
            Color color = model.getSelectedColor();
            area.append("new Color is = " + color);         
    });

  • How to prevent JFileChooser automatically changing to parent directory?

    When you show only directories, and click on the dir icons to navigate, and then dont select anything and click OK, it automatically 'cd's to the parent folder.
    My application is using the JFileChooser to let the user navigate through folders and certain details of 'foo' files in that folder are displayed in another panel.
    So we dont want the chooser automatically changing dir to parent when OK is clicked. How to prevent this behavior?
    I considered extending the chooser and looked at the Swing source code but it is hard to tell where the change dir is happening.
    thanks,
    Anil
    To demonstrate this, I took the standard JFileChooserDemo from the Sun tutorial and modified it adding these lines
              // NEW line 45 in constructor
              fc.addPropertyChangeListener((PropertyChangeListener) this);
              fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
          * NEW -
          * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
         public void propertyChange(PropertyChangeEvent e) {
              String prop = e.getPropertyName();
              if (JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(prop)) {
                   System.out.println("DIRECTORY_CHANGED_PROPERTY");
                   File file = (File) e.getNewValue();
                   System.out.println("DIRECTORY:" + file.getPath());
         }

    Here is the demo:
    package filechooser;
    import java.awt.BorderLayout;
    import java.awt.Insets;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.beans.PropertyChangeEvent;
    import java.beans.PropertyChangeListener;
    import java.io.File;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFileChooser;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.SwingUtilities;
    import javax.swing.UIManager;
    * FileChooserDemo.java uses these files:
    *   images/Open16.gif
    *   images/Save16.gif
    public class FileChooserDemo extends JPanel implements ActionListener,
              PropertyChangeListener {
         static private final String newline = "\n";
         JButton openButton, saveButton;
         JTextArea log;
         JFileChooser fc;
         public FileChooserDemo() {
              super(new BorderLayout());
              // Create the log first, because the action listeners
              // need to refer to it.
              log = new JTextArea(5, 20);
              log.setMargin(new Insets(5, 5, 5, 5));
              log.setEditable(false);
              JScrollPane logScrollPane = new JScrollPane(log);
              // Create a file chooser
              fc = new JFileChooser();
              // NEW
              fc.addPropertyChangeListener((PropertyChangeListener) this);
              fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
              // Create the open button. We use the image from the JLF
              // Graphics Repository (but we extracted it from the jar).
              openButton = new JButton("Open a File...",
                        createImageIcon("images/Open16.gif"));
              openButton.addActionListener(this);
              // Create the save button. We use the image from the JLF
              // Graphics Repository (but we extracted it from the jar).
              saveButton = new JButton("Save a File...",
                        createImageIcon("images/Save16.gif"));
              saveButton.addActionListener(this);
              // For layout purposes, put the buttons in a separate panel
              JPanel buttonPanel = new JPanel(); // use FlowLayout
              buttonPanel.add(openButton);
              buttonPanel.add(saveButton);
              // Add the buttons and the log to this panel.
              add(buttonPanel, BorderLayout.PAGE_START);
              add(logScrollPane, BorderLayout.CENTER);
          * NEW -
          * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
         public void propertyChange(PropertyChangeEvent e) {
              String prop = e.getPropertyName();
              // If the directory changed, don't show an image.
              if (JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(prop)) {
                   System.out.println("DIRECTORY_CHANGED_PROPERTY");
                   File file = (File) e.getNewValue();
                   System.out.println("DIRECTORY:" + file.getPath());
         public void actionPerformed(ActionEvent e) {
              // Handle open button action.
              if (e.getSource() == openButton) {
                   int returnVal = fc.showOpenDialog(FileChooserDemo.this);
                   if (returnVal == JFileChooser.APPROVE_OPTION) {
                        File file = fc.getSelectedFile();
                        // This is where a real application would open the file.
                        log.append("Opening: " + file.getName() + "." + newline);
                   } else {
                        log.append("Open command cancelled by user." + newline);
                   log.setCaretPosition(log.getDocument().getLength());
                   // Handle save button action.
              } else if (e.getSource() == saveButton) {
                   int returnVal = fc.showSaveDialog(FileChooserDemo.this);
                   if (returnVal == JFileChooser.APPROVE_OPTION) {
                        File file = fc.getSelectedFile();
                        // This is where a real application would save the file.
                        log.append("Saving: " + file.getName() + "." + newline);
                   } else {
                        log.append("Save command cancelled by user." + newline);
                   log.setCaretPosition(log.getDocument().getLength());
         /** Returns an ImageIcon, or null if the path was invalid. */
         protected static ImageIcon createImageIcon(String path) {
              java.net.URL imgURL = FileChooserDemo.class.getResource(path);
              if (imgURL != null) {
                   return new ImageIcon(imgURL);
              } else {
                   System.err.println("Couldn't find file: " + path);
                   return null;
          * Create the GUI and show it. For thread safety, this method should be
          * invoked from the event dispatch thread.
         private static void createAndShowGUI() {
              // Create and set up the window.
              JFrame frame = new JFrame("FileChooserDemo");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              // Add content to the window.
              frame.add(new FileChooserDemo());
              // Display the window.
              frame.pack();
              frame.setVisible(true);
         public static void main(String[] args) {
              // Schedule a job for the event dispatch thread:
              // creating and showing this application's GUI.
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        // Turn off metal's use of bold fonts
                        UIManager.put("swing.boldMetal", Boolean.FALSE);
                        createAndShowGUI();
    }

  • File Chooser in a Panel - please help

    Hello!
    I am implementing a FTP program as part of an assignment. Can you please tell me how I can get a File Chooser like interface to the files on the remote computer? Can the existing JFileChooser be modified to support this and also can it be embedded in a panel rather than opening in a separate dialog box? Is there any way to get drag and drop support in it?
    Please do help
    Thanks
    Dilip

    Hi!
    Actually, you can use JFileChooser for remote filesystems. I've implemented it once using JDK 1.3.1 (accessing a remote Linux machine over RMI in an applet):
    (1) Create your own subclass of java.io.File, hooking all methods that actually access the filesystem (isDirectory, getSize, ...) to your ftp-connection. (That's the main work, about 50 methods to overwrite, but you can skip many, e.g. createTemporaryFile).
    (2) Make your own subclass of FileSystemView to deliver objects of your File-class instead of Sun's.
    (3) Initialize JFileChooser with this FileSystemView.
    You may also take a look at
    http://www.crocodile.org/listok/2/WhatDoesFileSystemViewView.shtml .

  • JFileChooser problem - it will not display

    I have read the tutorial on JFileChoosers and understand the basics, however, my application will simply not display a File Chooser. I select the menu option "open file" and the command prompt window just spews out dozens of garbage. The code is below if there are any FileChooser "Pros" out there. The FileChooser is selected for loading in the actioPerformed method. Thanks for any assistance.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.JFileChooser;
    import javax.swing.filechooser.*;
    public class DissertationInterface extends JFrame implements ActionListener
         private JPanel onePanel, twoPanel, bottomPanel;
           private JButton quit,search;
           private JMenuBar TheMenu;
           private JMenu menu1, submenu;
         private JMenuItem menuItem1;
         private JFileChooser fc;          //FILE CHOOSER
           private BorderLayout layout;
           //Canvas that images should be drew on
           //drawTheImages Dti;
           //Instances of other classes
         //DatabaseComms2 db2 = new DatabaseComms2();
         //Configuration cF = new Configuration();
           public DissertationInterface()
                setTitle("Find My Pics - University Application") ;
                layout = new BorderLayout();          
                Container container = getContentPane();
                container.setLayout(layout);
                //Dti = new drawTheImages();
              //container.add(Dti);
                quit = new JButton("Quit");
                search = new JButton("Search");
                TheMenu = new JMenuBar();
                setJMenuBar(TheMenu);
                //FILE CHOOSER
                JFileChooser fc = new JFileChooser();     
                fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
                //First menu option = "File";
                menu1 = new JMenu("File");
              TheMenu.add(menu1);
                //Add an option to the Menu Item
                menuItem1 = new JMenuItem("OPEN FILE",KeyEvent.VK_T);
            menuItem1.setAccelerator(KeyStroke.getKeyStroke(
            KeyEvent.VK_1, ActionEvent.ALT_MASK));
              menu1.add(menuItem1);
              menuItem1.addActionListener(this);          //action listener for Open file option
                //CREATE 3 PANELS
                onePanel = new JPanel();
                onePanel.setBackground(Color.blue);
                onePanel.setLayout(new FlowLayout(FlowLayout.CENTER, 200, 400)) ;
                twoPanel = new JPanel();
                twoPanel.setBackground(Color.red);
                twoPanel.setLayout(new GridLayout(5,2,5,5));
                bottomPanel = new JPanel();
                bottomPanel.setBackground(Color.yellow);
                bottomPanel.setLayout(new FlowLayout(FlowLayout.CENTER,10,10));
              //ADD COMPONENTS TO THE PANELS
                //Add the menu bar and it's items to twoPanel
              twoPanel.add(TheMenu, BorderLayout.NORTH);
              twoPanel.setAlignmentY(LEFT_ALIGNMENT);
                bottomPanel.add(quit);
                quit.addActionListener(this);          //action listener for button
                bottomPanel.add(search);
                search.addActionListener(this);          //action listener for button
                //ADD PANELS TO THE WINDOWS
                container.add(onePanel, BorderLayout.CENTER);
                container.add(twoPanel,BorderLayout.NORTH);            
                container.add(bottomPanel, BorderLayout.SOUTH);
                //setSize(350,350);
                setVisible(true);
              }//END OF CONSTRUCTOR
            public void leaveWindow()
                 this.dispose() ;
            public static void main(String args[])
            DissertationInterface DI = new DissertationInterface();
            DI.setVisible(true);
            //Display the window.
            DI.setSize(450, 260);
            DI.setVisible(true);
            DI.pack();
         }//End of main method
         protected void processWindowEvent(WindowEvent e)
                super.processWindowEvent(e);
                if(e.getID()== WindowEvent.WINDOW_CLOSING)
                      System.exit(0);
              }//End of processWindowEvent
    //method to resolve button clicks etc
    public void actionPerformed(ActionEvent e)
              //PROBLEM IS HERE !!!!!!! - why won't the file dialogue box open
              if(e.getActionCommand().equals("OPEN"))
                   int returnVal = fc.showOpenDialog(DissertationInterface.this);
                 else if(e.getActionCommand().equals("Quit"))
                      //closeDialog();
                      System.out.println("User interface exited");
                      System.exit(1);
                      leaveWindow();
              else if(e.getActionCommand().equals("Search"))
                      //pass params to database                                 
                 }//end of else if
    } //end of method ActionPerformed
    }//End of class DissertationInterface

    I have done as stated, code compiles/executes but when I select the open file option on my GUI, the command prompt window freezes and no dialogue box is displayed!!!!

  • JFileChooser & XP look and feel

    Hello!
    I'm changing an exiting applet to have a local look & feel by simply doing this:
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); When the JFileChooser shows with the "metal" (java default) Look&Feel all is good but when it shows with
    XP (or windows) L&F it has added a "panel" on the left side with icons for "My Recent Document" , "Desktop" , "My Documents", "My Computer" and " My Network places".
    I really don't want them showing since it looks weird on the HTML page.
    Does somebody know if and how I can get rid of that "panel" and still have the rest of the L&F intact?
    Regards Calle

    Check out skin look and feel. They have all sorts of look and feels including windows XP.
    http://www.l2fprod.com

Maybe you are looking for

  • Resource Permission stored in DB

    Hi Everyone My customer is using a forms application that he needs to migrate to ADF. The new application should reuse the existing tables, PL/SQL APIs to such an extent that the old forms application should be available at the same time with the new

  • How to recover a lost LaunchPad configuration?

    I recently sent my Macbook Pro in for a repair, and I noticed upon receiving it that my Launchpad configuration has been lost.  I spent quite a lot of time putting it together, and can't seem to recover it.  I backed up my computer before I sent it o

  • How to change Approval mail title

    Dear all, I want to change approval sc mail title. So I changed Task 10008126. basic data-->work item text.. but still is old text after I get notification of shopping cart approval of email .who can tell me...how to active new text? Thanks a lot. Al

  • Firefox fonts in KDE extremely tiny

    I'm experiencing what seems to be a pretty common problem with the firefox fonts appearing really small in KDE.  I've tried several things:  Installed gtk-qt-engine --> That makes gtk apps look better in kde, but doesn't solve the firefox font proble

  • Listen to what is being recorded live, in iMovie

    Hi Can anyone advise whether it is possible to listen to what is being recorded whilst filming on iMovie as you would with a video camera? Thanks Dan