Java Code Examples for javax.swing.JFileChooser.ERROR_OPTION

The following are Jave code examples for showing how to use ERROR_OPTION of the javax.swing.JFileChooser class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: JavaGraph   File: SaveLTSAsDialog.java   Source Code and License Vote up 6 votes
@Override
public void actionPerformed(ActionEvent e) {
    JFileChooser chooser = GrooveFileChooser.getInstance();
    int result = chooser.showOpenDialog(SaveLTSAsDialog.this.simulator.getFrame());
    // now load, if so required
    if (result == JFileChooser.APPROVE_OPTION) {
        SaveLTSAsDialog.this.dirField.setText(chooser.getSelectedFile().getAbsolutePath());
    }
    if (result == JFileChooser.CANCEL_OPTION) {
        // System.out.println("Cancelled");
    }
    if (result == JFileChooser.ERROR_OPTION) {
        // System.out.println("Whooops");
    }

}
 
Example 2
Project: Equella   File: ImportPage.java   Source Code and License Vote up 6 votes
private File getFile(int reply, JFileChooser chooser, JTextField field, File oldFile)
{
	switch( reply )
	{
		case JFileChooser.ERROR_OPTION: {
			JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(this), "Error retrieving file", "Error",
				JOptionPane.ERROR_MESSAGE);
			field.setText("");
			return null;
		}
		case JFileChooser.APPROVE_OPTION: {
			File file = chooser.getSelectedFile();
			field.setText(file.getPath());
			return file;
		}
		case JFileChooser.CANCEL_OPTION: {
			return oldFile;
		}
	}
	field.setText("");
	return null;
}
 
Example 3
Project: geomapapp   File: DBInputDialog.java   Source Code and License Vote up 6 votes
public void loadExcelFile() {
	type = UnknownDataSet.EXCEL_FILE;
	jfc = haxby.map.MapApp.getFileChooser();
	jfc.setFileFilter(eff);
	int c = jfc.showOpenDialog(this);
	if (c==JFileChooser.CANCEL_OPTION || c == JFileChooser.ERROR_OPTION) {
		// If user cancels then close the dialog box also.
		input = null;
		setVisible(false);
		return;
	}
	path = jfc.getSelectedFile().getPath();
	if(jfc.getSelectedFile().getName().endsWith("xls")){
		loadExcelFile(jfc.getSelectedFile());
	}else if(jfc.getSelectedFile().getName().endsWith("xlsx")){
		loadExcelTypeXLSX(jfc.getSelectedFile());
	}else{
		return;
	}
}
 
Example 4
Project: jmt   File: Loader.java   Source Code and License Vote up 5 votes
/**
 * Shows a Load window and loads chosen model inside specified model data file
 * @param modelData data file where information should be stored. Note that <b>its type
 * must be compatible with defaultFilter chosen in the constructor</b>, otherwise a
 * ClassCastException will be thrown
 * @param parent parent component of loading window
 * @return SUCCESS on success, CANCELLED if loading is cancelled,
 * FAILURE if an error occurs and WARNING is one or more warnings are generated due to
 * format conversion
 * @throws ClassCastException if modelData is not of instance of the correct class
 * @see #getFailureMotivation getFailureMotivation()
 */
public int loadModel(Component parent) {
	warnings.clear();
	int status;
	status = this.showOpenDialog(parent);
	if (status == JFileChooser.CANCEL_OPTION) {
		return CANCELLED;
	} else if (status == JFileChooser.ERROR_OPTION) {
		failureMotivation = "Error selecting input file";
		return FAILURE;
	}

	f = dialog.getSelectedFile();

	try {
		if (defaultFilter == LOG) {

		}

	} catch (Exception e) {
		e.printStackTrace();
		failureMotivation = e.getClass().getName() + ": " + e.getMessage();
		return FAILURE;
	}
	// If no warnings were found, report success
	if (warnings.size() > 0) {
		return WARNING;
	} else {
		return SUCCESS;
	}
}
 
Example 5
Project: QN-ACTR-Release   File: Loader.java   Source Code and License Vote up 5 votes
/**
 * Shows a Load window and loads chosen model inside specified model data file
 * @param modelData data file where information should be stored. Note that <b>its type
 * must be compatible with defaultFilter chosen in the constructor</b>, otherwise a
 * ClassCastException will be thrown
 * @param parent parent component of loading window
 * @return SUCCESS on success, CANCELLED if loading is cancelled,
 * FAILURE if an error occurs and WARNING is one or more warnings are generated due to
 * format conversion
 * @throws ClassCastException if modelData is not of instance of the correct class
 * @see #getFailureMotivation getFailureMotivation()
 */
public int loadModel(Component parent) {
	warnings.clear();
	int status;
	status = this.showOpenDialog(parent);
	if (status == JFileChooser.CANCEL_OPTION) {
		return CANCELLED;
	} else if (status == JFileChooser.ERROR_OPTION) {
		failureMotivation = "Error selecting input file";
		return FAILURE;
	}

	f = dialog.getSelectedFile();

	try {
		if (defaultFilter == LOG) {

		}

	} catch (Exception e) {
		e.printStackTrace();
		failureMotivation = e.getClass().getName() + ": " + e.getMessage();
		return FAILURE;
	}
	// If no warnings were found, report success
	if (warnings.size() > 0) {
		return WARNING;
	} else {
		return SUCCESS;
	}
}
 
Example 6
Project: QN-ACTR-Release   File: ModelLoader.java   Source Code and License Vote up 5 votes
/**
 * Saves specified model into specified file or shows save as window if file is null
 * @param modelData data file where information should be stored. Note that <b>its type
 * must be compatible with defaultFilter chosen in the constructor</b>, otherwise a
 * ClassCastException will be thrown
 * @param parent parent window that will own the save as dialog
 * @param file location where pecified model must be saved or null if save as must be shown
 * @return SUCCESS on success, CANCELLED if loading is cancelled,
 * FAILURE if an error occurs
 * @throws ClassCastException if modelData is not of instance of the correct class
 * @see #getFailureMotivation getFailureMotivation()
 */
public int saveModel(Object modelData, Component parent, File file) {
	if (file == null) {
		// Shows save as window
		int status;
		status = this.showSaveDialog(parent);
		if (status == JFileChooser.CANCEL_OPTION) {
			return CANCELLED;
		} else if (status == JFileChooser.ERROR_OPTION) {
			failureMotivation = "Error selecting output file";
			return FAILURE;
		}
		file = dialog.getSelectedFile();
	} else
	// Check extension to avoid saving over a converted file
	if (!file.getName().endsWith(defaultFilter.getFirstExtension())) {
		int resultValue = JOptionPane.showConfirmDialog(parent, "<html>File <font color=#0000ff>" + file.getName() + "</font> does not have \""
				+ defaultFilter.getFirstExtension() + "\" extension.<br>Do you want to replace it anyway?</html>", "JMT - Warning",
				JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
		if (resultValue != JOptionPane.OK_OPTION) {
			return CANCELLED;
		}
	}

	// Now checks to save correct type of model
	try {
		if (defaultFilter == JMODEL || defaultFilter == JSIM) {
			XMLArchiver.saveModel(file, (CommonModel) modelData);
		} else if (defaultFilter == JMVA) {
			xmlutils.saveXML(((ExactModel) modelData).createDocument(), file);
		} else if (defaultFilter == JABA) {
			xmlutils.saveXML(((JabaModel) modelData).createDocument(), file);
		}
	} catch (Exception e) {
		failureMotivation = e.getClass().getName() + ": " + e.getMessage();
		return FAILURE;
	}
	return SUCCESS;
}
 
Example 7
Project: appinventor-extensions   File: AIMerger.java   Source Code and License Vote up 5 votes
private String getFileToOpen() {
  JFileChooser projectFC = new JFileChooser(browserPath);
  int validPath = projectFC.showOpenDialog(myCP);
  if (validPath == JFileChooser.ERROR_OPTION || validPath == JFileChooser.CANCEL_OPTION) {
    return null;
  } else {
    return projectFC.getSelectedFile().toString();
  }
}
 
Example 8
Project: appinventor-extensions   File: AIMerger.java   Source Code and License Vote up 5 votes
private String getFileToOpen() {
  JFileChooser projectFC = new JFileChooser();
  int validPath = projectFC.showOpenDialog(myCP);
  if (validPath == JFileChooser.ERROR_OPTION || validPath == JFileChooser.CANCEL_OPTION) {
    return null;
  } else {
    return projectFC.getSelectedFile().toString();
  }
}
 
Example 9
Project: geomapapp   File: DSDPDemo.java   Source Code and License Vote up 5 votes
public void exportExcel() {
	JFileChooser jfc = new JFileChooser(System.getProperty("user.dir"));
	ExcelFileFilter eff = new ExcelFileFilter();
	jfc.setFileFilter(eff);
	File f=new File("dsdpTable.xls");
	jfc.setSelectedFile(f);
	do {
		int c = jfc.showSaveDialog(null);
		if (c==JFileChooser.CANCEL_OPTION||c==JFileChooser.ERROR_OPTION) return;
		f = jfc.getSelectedFile();
		if (f.exists()) {
			c=JOptionPane.showConfirmDialog(null, "File Already Exists\nConfirm Overwrite");
			if (c==JOptionPane.OK_OPTION) break;
			if (c==JOptionPane.CANCEL_OPTION) return;
		}
	} while (f.exists());

	try {
		WritableWorkbook wb = Workbook.createWorkbook(f);
		WritableSheet sheet = wb.createSheet("First Sheet", 0);
		for (int i=0;i<table.getColumnCount();i++)
			sheet.addCell( new Label(i,0,table.getColumnName(i)) );
		for (int i=0;i<table.getRowCount();i++) {
			for (int j=0; j<table.getColumnCount();j++) {
				Object o = table.getValueAt(i, j);
				if (o == null || ( o instanceof String && ((String)o).equals("NaN") ) ) o = "";
				sheet.addCell( new Label(j,i+1,o.toString()) );
			}
		}
		wb.write();
		wb.close();
	} catch (Exception ex){
		ex.printStackTrace();
	}
}
 
Example 10
Project: geomapapp   File: AgeDepthModel.java   Source Code and License Vote up 5 votes
public void exportASCII() {
	JFileChooser jfc = new JFileChooser(System.getProperty("user.dir"));
	File f=new File(graphDialog.getTitle()+"_age_depth.txt");
	jfc.setSelectedFile(f);
	do {
		int c = jfc.showSaveDialog(null);
		if (c==JFileChooser.CANCEL_OPTION||c==JFileChooser.ERROR_OPTION) return;
		f = jfc.getSelectedFile();
		if (f.exists()) {
			c=JOptionPane.showConfirmDialog(null, "File Already Exists\nConfirm Overwrite");
			if (c==JOptionPane.OK_OPTION) break;
			if (c==JOptionPane.CANCEL_OPTION) return;
		}
	} while (f.exists());

	try {
		BufferedWriter out = new BufferedWriter(new FileWriter(f));
		out.write("ID\tdepth\tage\tsource\n");
		float[] firstTie = (float[])ties.get(0);
		String sourceString = (String)holeSources.get(0);
		out.write(graphDialog.getTitle() + "\t" + firstTie[0] + "\t" + firstTie[1] + "\t" + sourceString + "\n");
		for( int i=0 ; i<ties.size() ; i++) {
			float[] tie = (float[])ties.get(i);
			out.write("\t" + tie[0] + "\t" + tie[1] + "\t\n");
		}
		out.close();
	} catch (IOException ex){

	}
}
 
Example 11
Project: geomapapp   File: OtherDBInputDialog.java   Source Code and License Vote up 5 votes
public void loadFile(){
	type = UnknownDataSet.ASCII_FILE;
	jfc.setFileFilter(null);
	int c = jfc.showOpenDialog(this);
	if (c==JFileChooser.CANCEL_OPTION || c == JFileChooser.ERROR_OPTION) return;
	path = jfc.getSelectedFile().getPath();
	loadFile(jfc.getSelectedFile());
}
 
Example 12
Project: geomapapp   File: OtherDBInputDialog.java   Source Code and License Vote up 5 votes
public void loadExcelFile() {
	type = UnknownDataSet.EXCEL_FILE;
	jfc.setFileFilter(eff);
	int c = jfc.showOpenDialog(this);
	if (c==JFileChooser.CANCEL_OPTION || c == JFileChooser.ERROR_OPTION) return;
	path = jfc.getSelectedFile().getPath();
	loadExcelFile(jfc.getSelectedFile());
}
 
Example 13
Project: geomapapp   File: DBInputDialog.java   Source Code and License Vote up 5 votes
public void loadFile(){
	type = UnknownDataSet.ASCII_FILE;
	jfc = haxby.map.MapApp.getFileChooser();
	jfc.setFileFilter(null);
	int c = jfc.showOpenDialog(this);
	if (c==JFileChooser.CANCEL_OPTION || c == JFileChooser.ERROR_OPTION) {
		return;
	}
	path = jfc.getSelectedFile().getPath();
	loadFile(jfc.getSelectedFile());
}
 
Example 14
Project: geomapapp   File: UnknownDataSet.java   Source Code and License Vote up 5 votes
public void exportASCII(String saveOption){
	//run standard checks before exporting
	if (!exportChecks(saveOption)) return;
	
	JFileChooser jfc = new JFileChooser(System.getProperty("user.home"));
	File f=new File(desc.name.replace(":", "")+".txt");
	jfc.setSelectedFile(f);
	do {
		int c = jfc.showSaveDialog(null);
		if (c==JFileChooser.CANCEL_OPTION||c==JFileChooser.ERROR_OPTION) return;
		f = jfc.getSelectedFile();
		if (f.exists()) {
			c=JOptionPane.showConfirmDialog(null, "File Already Exists\nConfirm Overwrite");
			if (c==JOptionPane.OK_OPTION) break;
			if (c==JOptionPane.CANCEL_OPTION) return;
		}
	} while (f.exists());

	try {
		BufferedWriter out = new BufferedWriter(new FileWriter(f));
		//don't include Plot column
		for (int i=1;i<dataT.getColumnCount();i++)
			out.write(dataT.getColumnName(i)+"\t");
		out.write("\n");
		
		int[] ind;
		if (saveOption.equals("selection")) {
			ind = dataT.getSelectedRows();
		} else if (saveOption.equals("plottable")) {
			ind = getPlottableRows();
		} else {
			ind = new int[dataT.getRowCount()];
			for (int i=0; i<dataT.getRowCount(); i++) ind[i] = i;
		}
			
		for (int i=0;i<ind.length;i++) {
			for (int j=1; j<dataT.getColumnCount();j++) {
				Object o = dataT.getValueAt(ind[i], j);
				if (o instanceof String && ((String)o).equals("NaN")) o = "";
				out.write(o+"\t");
			}
			out.write("\n");
		}
		out.close();
	} catch (IOException ex){

	}
}
 
Example 15
Project: geomapapp   File: DSDPDemo.java   Source Code and License Vote up 4 votes
public void exportSelectExcel(){
	if (table.getSelectedRowCount() == 0) {
		JOptionPane.showMessageDialog(null, "No data selected for export", "No Selection", JOptionPane.ERROR_MESSAGE);
		return;
	}

	JFileChooser jfc = new JFileChooser(System.getProperty("user.dir"));
	ExcelFileFilter eff = new ExcelFileFilter();
	jfc.setFileFilter(eff);
	File f=new File("dsdpTableSelection.xls");
	jfc.setSelectedFile(f);
	do {
		int c = jfc.showSaveDialog(null);
		if (c==JFileChooser.CANCEL_OPTION||c==JFileChooser.ERROR_OPTION) return;
		f = jfc.getSelectedFile();
		if (f.exists()) {
			c=JOptionPane.showConfirmDialog(null, "File Already Exists\nConfirm Overwrite");
			if (c==JOptionPane.OK_OPTION) break;
			if (c==JOptionPane.CANCEL_OPTION) return;
		}
	} while (f.exists());

	try {
		WritableWorkbook wb = Workbook.createWorkbook(f);
		WritableSheet sheet = wb.createSheet("First Sheet", 0);
		for (int i=0;i<table.getColumnCount();i++)
			sheet.addCell( new Label(i,0,table.getColumnName(i)) );
		int sel[] = table.getSelectedRows();
		for (int i=0;i<sel.length;i++) {
			for (int j=0; j<table.getColumnCount();j++) {
				Object o = table.getValueAt(sel[i], j);
				if (o == null || ( o instanceof String && ((String)o).equals("NaN") ) ) o = "";
				sheet.addCell( new Label(j,i+1,o.toString()) );
			}
		}
		wb.write();
		wb.close();
	} catch (Exception ex){
		ex.printStackTrace();
	}
}
 
Example 16
Project: geomapapp   File: SurveyPlannerDataDisplay.java   Source Code and License Vote up 4 votes
private void saveToFile() {

		JFileChooser jfc = new JFileChooser(System.getProperty("user.home"));
		File f=new File("SurveyLines.txt");
		jfc.setSelectedFile(f);
		do {
			int c = jfc.showSaveDialog(null);
			if (c==JFileChooser.CANCEL_OPTION||c==JFileChooser.ERROR_OPTION) return;
			f = jfc.getSelectedFile();
			if (f.exists()) {
				c=JOptionPane.showConfirmDialog(null, "File Already Exists\nConfirm Overwrite");
				if (c==JOptionPane.OK_OPTION) break;
				if (c==JOptionPane.CANCEL_OPTION) return;
			}
		} while (f.exists());

		try {
			BufferedWriter out = new BufferedWriter(new FileWriter(f));
			
			//add disclaimer at the top of the output file
			out.write("NOT TO BE USED FOR NAVIGATION PURPOSES\n");
			boolean firstCol = true;
			for (int i=0;i<tm.getColumnCount();i++) {
				if (i == sp.getSurveyLineColumn()) continue;
				if (firstCol) {
					out.write(tm.getColumnName(i));
					firstCol = false;
				} else {
					out.write("," + tm.getColumnName(i));
				}
			}
			out.write("\n");
			
			int[] ind;
			ind = new int[tm.getRowCount()];
			for (int i=0; i<tm.getRowCount(); i++) ind[i] = i;
			
			for (int i=0;i<tm.getRowCount();i++) {
				firstCol = true;
				for (int j=0; j<tm.getColumnCount();j++) {
					if (j == sp.getSurveyLineColumn()) continue;
					Object o = tm.getValueAt(i, j);
					if (o instanceof String && ((String)o).equals("NaN")) o = "";
					if (firstCol) {
						out.write(o.toString());
						firstCol = false;
					} else {
						out.write(","+ o);
					}
				}
				out.write("\n");
			}
			out.close();
		} catch (IOException e){
			JOptionPane.showMessageDialog(panel, "Unable to save file", "Save Error", JOptionPane.ERROR_MESSAGE);
			System.out.println(e);
		}
	}
 
Example 17
Project: geomapapp   File: KMLExport.java   Source Code and License Vote up 4 votes
public static void exportToKML(UnknownDataSet ds, DataSelector select) {
	KMLExportConfigDialog fc = null;
	HeaderConfig hc = null;

	// Set up the headers and fields
	do {
		if (hc == null)
			hc = new HeaderConfig((JFrame)ds.map.getTopLevelAncestor(),ds);
		else
			hc.setVisible(true);
		if (hc.visibleV == null) {
			hc.dispose();
			return;
		}

		int imgI = guessImage(ds, hc.visibleV, select);
		fc = new KMLExportConfigDialog((JFrame) ds.map.getTopLevelAncestor(), 
				ds.desc.name.replace(":", ""), hc.visibleV, imgI);
	} while (!fc.export);
	hc.dispose();

	// Get the save file
	JFileChooser jfc = new JFileChooser(System.getProperty("user.home"));
	File f = new File(ds.desc.name.split("\\s")[0] + ".kmz");
	jfc.setSelectedFile(f);

	do {
		int c = jfc.showSaveDialog(null);
		if (c==JFileChooser.CANCEL_OPTION||c==JFileChooser.ERROR_OPTION) return;
		f = jfc.getSelectedFile();
		if (f.exists()) {
			c=JOptionPane.showConfirmDialog(null, "File Already Exists\nConfirm Overwrite");
			if (c==JOptionPane.OK_OPTION) break;
			// if (c==JOptionPane.CANCEL_OPTION) return;
		}
	} while (f.exists());

	int n = 1 + fc.getScales().size();
	n *= select.getRowCount();

	JDialog dialog = new JDialog((JFrame) ds.map.getTopLevelAncestor());
	dialog.setTitle("Exporting to KMZ");
	dialog.setModal(true);
	JProgressBar pb = new JProgressBar(0,n);
	JPanel p = new JPanel();
	p.add(new JLabel("Saving " + f.getName()));
	p.add(pb);

	dialog.getContentPane().setLayout(new FlowLayout());
	dialog.getContentPane().add(p);
	dialog.pack();
	dialog.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
	dialog.setLocation(dialog.getOwner().getX() + dialog.getOwner().getWidth() / 2 - dialog.getWidth()/2, 
			dialog.getOwner().getY() + dialog.getOwner().getHeight() / 2 - dialog.getHeight()/2);

	new Task(new Object[] {ds,select,f,fc,hc,pb,dialog}) {
		public void run() {
			exportToKML((UnknownDataSet)args[0],
					(DataSelector)args[1],
					(File)args[2],
					(KMLExportConfigDialog)args[3],
					(HeaderConfig)args[4],
					(JProgressBar)args[5]);
			((JDialog) args[6]).dispose();
		}
	}.start();
	dialog.setVisible(true);
}
 
Example 18
Project: geomapapp   File: UnknownDataSet.java   Source Code and License Vote up 4 votes
public void exportExcel(String saveOption){
	//run standard checks before exporting
	if (!exportChecks(saveOption)) return;
	
	JFileChooser jfc = new JFileChooser(System.getProperty("user.home"));
	ExcelFileFilter eff = new ExcelFileFilter();
	jfc.setFileFilter(eff);
	File f=new File(desc.name.replace(":", "")+".xls");
	jfc.setSelectedFile(f);
	do {
		int c = jfc.showSaveDialog(null);
		if (c==JFileChooser.CANCEL_OPTION||c==JFileChooser.ERROR_OPTION) return;
		f = jfc.getSelectedFile();
		if (f.exists()) {
			c=JOptionPane.showConfirmDialog(null, "File Already Exists\nConfirm Overwrite");
			if (c==JOptionPane.OK_OPTION) break;
			if (c==JOptionPane.CANCEL_OPTION) return;
		}
	} while (f.exists());

	try { 
		WritableWorkbook wb = Workbook.createWorkbook(f);
		WritableSheet sheet = wb.createSheet("First Sheet", 0);
		//don't include Plot column
		for (int i=1;i<dataT.getColumnCount();i++)
			sheet.addCell( new Label(i-1,0,dataT.getColumnName(i)) );
		
		int[] ind;
		if (saveOption.equals("selection")) {
			ind = dataT.getSelectedRows();
		} else if (saveOption.equals("plottable")) {
			ind = getPlottableRows();
		} else {
			ind = new int[dataT.getRowCount()];
			for (int i=0; i<dataT.getRowCount(); i++) ind[i] = i;
		}
			
		for (int i=0;i<ind.length;i++) {
			for (int j=1; j<dataT.getColumnCount();j++) {
				Object o = dataT.getValueAt(ind[i], j);
				if (o instanceof String && ((String)o).equals("NaN")) o = "";
				sheet.addCell( new Label(j-1,i+1,o.toString()) );
			}
		}
		wb.write();
		wb.close();
	} catch (Exception ex){
		ex.printStackTrace();
	}
}
 
Example 19
Project: geomapapp   File: UnknownDataSet.java   Source Code and License Vote up 4 votes
public void exportExcelXLSX(String saveOption){
	//run standard checks before exporting
	if (!exportChecks(saveOption)) return;

	JFileChooser jfc = new JFileChooser(System.getProperty("user.home"));
	ExcelFileFilter eff = new ExcelFileFilter();
	jfc.setFileFilter(eff);
	String defaultName = desc.name.replace(":", "") + ".xlsx";

	if(defaultName.contains("Data Table ")){
		defaultName = defaultName.replace("Data Table ", "");
	}

	File f=new File(defaultName);
	jfc.setSelectedFile(f);
	do {
		int c = jfc.showSaveDialog(null);
		if (c==JFileChooser.CANCEL_OPTION||c==JFileChooser.ERROR_OPTION) return;
		f = jfc.getSelectedFile();
		if (f.exists()) {
			c=JOptionPane.showConfirmDialog(null, "File Already Exists\nConfirm Overwrite");
			if (c==JOptionPane.OK_OPTION)break;
			if (c==JOptionPane.CANCEL_OPTION) return;
		}
	} while (f.exists());

	try {
		if (!f.getName().endsWith(".xlsx")){
			System.out.println(f.getName());
			JOptionPane.showMessageDialog(null, "Save did not complete. Must end in .xlsx. Try again.");
		}else{
			XSSFWorkbook xlsxWB = new XSSFWorkbook();
			CreationHelper createHelper = xlsxWB.getCreationHelper();
			XSSFSheet xlsxSheet1 = xlsxWB.createSheet("First Sheet");
			Row row = null;
			
			int[] ind;
			if (saveOption.equals("selection")) {
				ind = dataT.getSelectedRows();
			} else if (saveOption.equals("plottable")) {
				ind = getPlottableRows();
			} else {
				ind = new int[dataT.getRowCount()];
				for (int i=0; i<dataT.getRowCount(); i++) ind[i] = i;
			}
			int xlsxCol = dataT.getColumnCount();
			row = xlsxSheet1.createRow((0));
			//don't include Plot column
			for (int c=1; c<xlsxCol; c++){
				String columnName = dataT.getColumnName(c);
				row.createCell(c-1).setCellValue(columnName);
			}

			for (int r=1; r<=ind.length; r++){
				row = xlsxSheet1.createRow((r));
				for (int c=1; c<xlsxCol; c++){
					Object o = dataT.getValueAt(ind[r-1], c);
					String input1 = null;
					if(o instanceof String && ((String)o).equals("NaN")){
						o = "";
						input1 = o.toString();
						row.createCell(c-1).setCellValue(input1);
					}else if(o instanceof String){
						row.createCell(c-1).setCellValue((String)o);
					}
				}
			}
			FileOutputStream xlsxOut = new FileOutputStream(f);
			xlsxWB.write(xlsxOut);
			xlsxOut.close();
		}
	} catch (Exception ex){
		ex.printStackTrace();
	}
}