showOpenDialog Question
From: J.Storta (john.storta_at_jstorta.com)
Date: 11/27/04
- Previous message: VK: "Re: transmit gprs-data (from mobile to server)"
- Next in thread: Andrew Thompson: "Re: showOpenDialog Question"
- Reply: Andrew Thompson: "Re: showOpenDialog Question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 27 Nov 2004 05:58:08 -0800
I am new to Java.
I have been working through some tutorials and I am trying to make
modifications to test my understanding of some of the concepts. I am
having trouble with something.
Below is a piece of code for an application. For the purpose of
brevity on this post, I removed some of the code that I didn't think
was relevent to this question.
The problem I am having as to do with the showOpenDialog call in the
buildMenu() method.
According to the documentation, the method takes a parameter of the
parent component, but it also accepts null.
I can get the code to work as expected by passing null, but I am not
sure why it fails when I pass a parameter of 'this'.
Ths is the error I get at compile time.
----
showOpenDialog(java.awt.Component) in javax.swing.JFileChooser cannot
be applied to (<anonymous java.awt.event.ActionListener>)
----
Any insight would be appreciated.
Thanks.
Here is the code
------------
package mypackage;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MyPackage extends JFrame
{
private JTabbedPane tabbedPane;
public MyPackage()
{
super("My First Package");
//Create the tabs
tabbedPane = new JTabbedPane(SwingConstants.TOP);
tabbedPane.setBackground(Color.yellow);
tabbedPane.setForeground(Color.black);
populateTabbedPane();
buildMenu();
getContentPane().add(tabbedPane);
pack();
}
private void populateTabbedPane()
{
//Tabs
}
private void buildMenu()
{
JMenuBar mb = new JMenuBar();
JMenu fileMenu = new JMenu("File");
JMenuItem fileItem = new JMenuItem("Open");
fileItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JFileChooser fileOpen = new JFileChooser();
int returnVal = fileOpen.showOpenDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION)
{
System.out.println("You chose to open this file: " +
fileOpen.getSelectedFile().getName());
}
}
});
fileMenu.add(fileItem);
setJMenuBar(mb);
}
public static void main(String[] args)
{
MyPackage mp = new MyPackage();
mp.setLocation(175, 50);
mp.setSize(600, 500);
mp.setBackground(Color.magenta);
mp.setVisible(true);
}
}
- Previous message: VK: "Re: transmit gprs-data (from mobile to server)"
- Next in thread: Andrew Thompson: "Re: showOpenDialog Question"
- Reply: Andrew Thompson: "Re: showOpenDialog Question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]