CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Jan 2009
    Posts
    3

    JFileChooser Actionlistener

    Hello,

    While programming in Java i ran into a problem concerning a JFileChooser and it's actionListener.

    The problem is, that my Actionlistener only seems to listen to the events made by my JFileChoosers 'close' button.

    As you can see in my actionlistener im printing a line which should display "Display Test".

    But this only happens when i click the close button, and not when i use the open button.

    I would appriciate any help you can give me.

    //Java Code FileChooser.java
    Code:
    package View;
    
    import Controller.CFileChooser;
    import java.awt.Container;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JButton;
    import javax.swing.JFileChooser;
    import javax.swing.JLabel;
    
    
    public class FileChooser
    			extends		JFrame
    			implements	ActionListener
    {
    	// GUI
        private JFileChooser FSFileChooser;
    
    	// Instantievariabele
            private CFileChooser _controller;
    	public FileChooser(CFileChooser controller)
    	{
            super();
            _controller = controller;
    		// Geef het frame een titel en zet de afmetingen
    		setTitle("Pick your *.leg File!");
    		setBounds(320,20,500,400);
                    setDefaultCloseOperation(EXIT_ON_CLOSE);
    
    		Container pane = getContentPane();
    
    		pane.setLayout(null);
    
    	FSFileChooser = new JFileChooser();
            FSFileChooser.addActionListener(this);
            FSFileChooser.setBounds(0,0,500,370);
            FSFileChooser.setVisible(true);
            FSFileChooser.setMultiSelectionEnabled(false);
            pane.add(FSFileChooser);
    	}
    
        public void actionPerformed(ActionEvent e)
        {
            System.out.println("Display Test");
            //String command = e.getActionCommand();
            //if (command.equals(JFileChooser.CANCEL_SELECTION)) {
            //  System.out.println(JFileChooser.CANCEL_SELECTION);
            //}
        }
    }
    //End Java Code

    Greetings Dennis
    Last edited by Tyranox; January 13th, 2009 at 08:57 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured