I am using netbeans for developing java dextop application,I have created a JFilechooser which will let user to save a new file created.
But the this int returnVal = newFileChooser.showSaveDialog(this); line of the following code gives this error:
method showSaveDialog in javax.swing.JFileChooser cannot be applied to given types required: java.awt.Component found: netsim.NetSimView
here class name is NetSimView and source package is netsim
private void newMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
newFileChooser=new JFileChooser();
int returnVal = newFileChooser.showSaveDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = newFileChooser.getSelectedFile();
} else {
System.out.println("File access cancelled by user.");
}
}
How to fix this error?
It’s expecting an instance of
java.awt.Componentas argument inshowSaveDialog()method, but you aren’t passing a valid argument.You have 2 options:
Just pass
nullinstead ofthis.Let the class
netsim.NetSimViewextend ajava.awt.Component.Hint: those blueish code things in the 1st sentence are actually links. Click and learn.