List of usage examples for javax.swing JFileChooser showOpenDialog
public int showOpenDialog(Component parent) throws HeadlessException
From source file:GroupProject.OriginalChartUI.java
private void localBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_localBrowseButtonActionPerformed // TODO add your handling code here: JFileChooser fileChooser = new JFileChooser(); FileTypeFilter fileFileter = new FileTypeFilter(); fileChooser.setFileFilter(fileFileter); int returnVal = fileChooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fileChooser.getSelectedFile(); // FileName.setText(file.getName()); //FileUpload.Upload(file); localDataResourceAddr.setText(file.getName()); } else {/*w w w . j a v a 2 s . c o m*/ JOptionPane.showMessageDialog(null, "File access cancelled by user.", "Alert", JOptionPane.ERROR_MESSAGE); } }
From source file:com.wet.wired.jsr.player.JPlayer.java
public void actionPerformed(ActionEvent ev) { if (ev.getActionCommand().equals("open")) { UIManager.put("FileChooser.readOnly", true); JFileChooser fileChooser = new JFileChooser(); FileExtensionFilter filter = new FileExtensionFilter(); filter = new FileExtensionFilter(); filter.addExtension("owl"); filter.setDescription("TestingOwl File"); if (target != null) { fileChooser.setSelectedFile(new File(target + ".owl")); }/*from www. j av a2 s . c o m*/ fileChooser.setFileFilter(filter); fileChooser.setCurrentDirectory(new File(".")); fileChooser.showOpenDialog(this); if (fileChooser.getSelectedFile() != null) { // target = fileChooser.getSelectedFile().getAbsolutePath(); String targetCapOwl = fileChooser.getSelectedFile().getAbsolutePath(); target = targetCapOwl.substring(0, targetCapOwl.lastIndexOf(".owl")); open(); } } else if (ev.getActionCommand().equals("play")) { play(); } else if (ev.getActionCommand().equals("reset")) { reset(); } else if (ev.getActionCommand().equals("fastForward")) { fastForward(); } else if (ev.getActionCommand().equals("pause")) { pause(); } else if (ev.getActionCommand().equals("close")) { close(); } else if (ev.getActionCommand().equals("recorder")) { closePlayer(); Main.getRecorder().init(new String[0]); } }
From source file:cn.labthink.ReadAccess060.java
private void jButton_OpenfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_OpenfileActionPerformed //filter/*from w w w. j av a2 s . co m*/ ExtensionFileFilter filter = new ExtensionFileFilter("mdb", false, true); filter.setDescription("Open DataBase File"); //? JFileChooser jfc = new JFileChooser(); FileSystemView fsv = FileSystemView.getFileSystemView(); //? jfc.setCurrentDirectory(fsv.getHomeDirectory()); jfc.setDialogTitle("Choose the mdb file"); jfc.setMultiSelectionEnabled(false); jfc.setDialogType(JFileChooser.OPEN_DIALOG); jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); jfc.setFileFilter(filter); int result = jfc.showOpenDialog(this); // ""? if (result == JFileChooser.APPROVE_OPTION) { String filesrc = jfc.getSelectedFile().getAbsolutePath(); inputfile = jfc.getSelectedFile(); jLabel_dbpath.setText("DB File Path:" + filesrc); maxid = Integer.MIN_VALUE; minid = Integer.MAX_VALUE; } else { return; } // Infodata = new Vector(); Infocolumns = new Vector(); try { // String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=D://b.MDB"; if (inputfile == null) { return; } initDB(); sql = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); rs = sql.executeQuery("SELECT * FROM test order by testid desc"); Infocolumns.add("TestID"); Infocolumns.add("TestType"); Infocolumns.add("DeviceID"); Infocolumns.add("CellID"); Infocolumns.add("Operator"); Infocolumns.add("StartTime"); Infocolumns.add("EndTime"); Infocolumns.add("Comments"); Infocolumns.add("SetTemp."); int columnCount = Infocolumns.size(); Vector row; while (rs.next()) { row = new Vector(columnCount); int temp = 0; int ivalue = rs.getInt("TESTID"); maxid = maxid < ivalue ? ivalue : maxid; minid = minid > ivalue ? ivalue : minid; row.add(ivalue); temp = rs.getInt("TESTTYPE"); if (temp == 1) { row.add("OTR"); } else if (temp == 2) { row.add("WVTR"); } else { row.add(temp); } row.add(rs.getInt("DEVICEID")); row.add(rs.getString("CELLID")); row.add(rs.getString("OPERATOR")); row.add(rs.getDate("STARTTIME")); row.add(rs.getDate("ENDTIME")); row.add(rs.getString("COMMENTS")); row.add(rs.getDouble("SETTEMP")); // row.add(rs.getString(11)); // row.add(rs.getInt(10)); Infodata.add(row); } DefaultTableModel tableModel = new DefaultTableModel(Infodata, Infocolumns); jTable1.setModel(tableModel); //? // jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); jTable1.setSelectionBackground(Color.orange); //? TableRowSorter<TableModel> tableRowSorter = new TableRowSorter<TableModel>(tableModel); jTable1.setRowSorter(tableRowSorter); // jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); //table DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();// table tcr.setHorizontalAlignment(SwingConstants.CENTER);// ?? jTable1.setDefaultRenderer(Object.class, tcr); // ((DefaultTableCellRenderer) jTable1.getTableHeader().getDefaultRenderer()) .setHorizontalAlignment(SwingConstants.CENTER); // DefaultTableCellRenderer rh = new DefaultTableCellRenderer(); // rh.setHorizontalAlignment(SwingConstants.CENTER); // jTable1.getTableHeader().setDefaultRenderer(rh); jTable1.getColumnModel().getColumn(0).setPreferredWidth(20); jTable1.getColumnModel().getColumn(1).setPreferredWidth(28); jTable1.getColumnModel().getColumn(2).setPreferredWidth(20); jTable1.getColumnModel().getColumn(3).setPreferredWidth(40); jTable1.getColumnModel().getColumn(4).setPreferredWidth(40); jTable1.getColumnModel().getColumn(5).setPreferredWidth(100); jTable1.getColumnModel().getColumn(6).setPreferredWidth(100); jTable1.getColumnModel().getColumn(7).setPreferredWidth(100); } catch (SQLException ee) { System.out.println(ee); } catch (ClassNotFoundException ex) { Logger.getLogger(ReadAccess060.class.getName()).log(Level.SEVERE, null, ex); } finally { try { sql.close(); } catch (Exception e) { } try { rs.close(); } catch (Exception e) { } } // validate(); }
From source file:cn.labthink.ReadAccess330.java
private void jButton_OpenfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_OpenfileActionPerformed //filter/* w w w .ja v a 2 s . c om*/ ExtensionFileFilter filter = new ExtensionFileFilter("mdb", false, true); filter.setDescription("Open DataBase File"); //? JFileChooser jfc = new JFileChooser(); FileSystemView fsv = FileSystemView.getFileSystemView(); //? jfc.setCurrentDirectory(fsv.getHomeDirectory()); jfc.setDialogTitle("Choose the mdb file"); jfc.setMultiSelectionEnabled(false); jfc.setDialogType(JFileChooser.OPEN_DIALOG); jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); jfc.setFileFilter(filter); int result = jfc.showOpenDialog(this); // ""? if (result == JFileChooser.APPROVE_OPTION) { String filesrc = jfc.getSelectedFile().getAbsolutePath(); inputfile = jfc.getSelectedFile(); jLabel_dbpath.setText("DB File Path:" + filesrc); maxid = Integer.MIN_VALUE; minid = Integer.MAX_VALUE; } else { return; } // Infodata = new Vector(); Infocolumns = new Vector(); try { // String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=D://b.MDB"; if (inputfile == null) { return; } initDB(); sql = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); rs = sql.executeQuery("SELECT * FROM test order by testid desc"); Infocolumns.add("TestID"); Infocolumns.add("TestType"); Infocolumns.add("DeviceID"); Infocolumns.add("CellID"); Infocolumns.add("Operator"); Infocolumns.add("StartTime"); Infocolumns.add("EndTime"); Infocolumns.add("Comments"); Infocolumns.add("SetTemp."); int columnCount = Infocolumns.size(); Vector row; while (rs.next()) { row = new Vector(columnCount); int temp = 0; int ivalue = rs.getInt("TESTID"); maxid = maxid < ivalue ? ivalue : maxid; minid = minid > ivalue ? ivalue : minid; row.add(ivalue); temp = rs.getInt("TESTTYPE"); if (temp == 1) { row.add("OTR"); } else if (temp == 2) { row.add("WVTR"); } else { row.add(temp); } row.add(rs.getInt("DEVICEID")); row.add(rs.getString("CELLID")); row.add(rs.getString("OPERATOR")); row.add(rs.getDate("STARTTIME")); row.add(rs.getDate("ENDTIME")); row.add(rs.getString("COMMENTS")); row.add(rs.getDouble("SETTEMP")); // row.add(rs.getString(11)); // row.add(rs.getInt(10)); Infodata.add(row); } DefaultTableModel tableModel = new DefaultTableModel(Infodata, Infocolumns); jTable1.setModel(tableModel); //? // jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); jTable1.setSelectionBackground(Color.orange); //? TableRowSorter<TableModel> tableRowSorter = new TableRowSorter<TableModel>(tableModel); jTable1.setRowSorter(tableRowSorter); // jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); //table DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();// table tcr.setHorizontalAlignment(SwingConstants.CENTER);// ?? jTable1.setDefaultRenderer(Object.class, tcr); // ((DefaultTableCellRenderer) jTable1.getTableHeader().getDefaultRenderer()) .setHorizontalAlignment(SwingConstants.CENTER); // DefaultTableCellRenderer rh = new DefaultTableCellRenderer(); // rh.setHorizontalAlignment(SwingConstants.CENTER); // jTable1.getTableHeader().setDefaultRenderer(rh); jTable1.getColumnModel().getColumn(0).setPreferredWidth(20); jTable1.getColumnModel().getColumn(1).setPreferredWidth(28); jTable1.getColumnModel().getColumn(2).setPreferredWidth(20); jTable1.getColumnModel().getColumn(3).setPreferredWidth(40); jTable1.getColumnModel().getColumn(4).setPreferredWidth(40); jTable1.getColumnModel().getColumn(5).setPreferredWidth(100); jTable1.getColumnModel().getColumn(6).setPreferredWidth(100); jTable1.getColumnModel().getColumn(7).setPreferredWidth(100); } catch (SQLException ee) { System.out.println(ee); } catch (ClassNotFoundException ex) { Logger.getLogger(ReadAccess330.class.getName()).log(Level.SEVERE, null, ex); } finally { try { sql.close(); } catch (Exception e) { } try { rs.close(); } catch (Exception e) { } } // validate(); }
From source file:com.t3.client.ui.ExportDialog.java
public void browseButtonAction() { JFileChooser chooser = new JFileChooser(); if (exportLocation instanceof LocalLocation) { chooser.setSelectedFile(((LocalLocation) exportLocation).getFile()); }//w ww. j a v a 2 s .co m if (chooser.showOpenDialog(ExportDialog.this) == JFileChooser.APPROVE_OPTION) { interactPanel.setText("locationTextField", chooser.getSelectedFile().getAbsolutePath()); } }
From source file:jmemorize.gui.swing.frames.MainFrame.java
@Override public File determineLessonFileToOpen() { // from determineLessonFile(file): final File lessonFile; final JFileChooser chooser = new JFileChooser(); try {// w w w . jav a 2 s . c o m chooser.setCurrentDirectory(Settings.loadLastDirectory()); } catch (final Exception ioe) { Main.logThrowable("Could not load last directory", ioe); chooser.setCurrentDirectory(null); } chooser.setFileFilter(MainFrame.FILE_FILTER); final int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { lessonFile = chooser.getSelectedFile(); } else { lessonFile = null; } return lessonFile; }
From source file:com.sshtools.common.ui.SshToolsApplicationClientPanel.java
/** * *///w w w . jav a 2s. c om public void open() { // Create a file chooser with the current directory set to the // application home String prefsDir = super.getApplication().getApplicationPreferencesDirectory().getAbsolutePath(); JFileChooser fileDialog = new JFileChooser(prefsDir); fileDialog.setFileFilter(connectionFileFilter); // Show it int ret = fileDialog.showOpenDialog(this); // If we've approved the selection then process if (ret == fileDialog.APPROVE_OPTION) { PreferencesStore.put(PREF_CONNECTION_FILE_DIRECTORY, fileDialog.getCurrentDirectory().getAbsolutePath()); // Get the file File f = fileDialog.getSelectedFile(); open(f); } }
From source file:com.claim.ui.UiReportType5.java
private void jButtonFolder3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonFolder3ActionPerformed try {//from ww w. j a v a2 s . co m JFileChooser fc = new JFileChooser(); fc.setDialogTitle("Open Folder"); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setCurrentDirectory(new File("")); int result = fc.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { File a = fc.getSelectedFile(); // Path File method in this class String temp = a.getPath(); txtPathFileType5.setText("."); if (temp != null) { txtPathFileType5.setText(temp); //txtPathFileOpaeIndv.setEnabled(true); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.att.aro.ui.view.menu.tools.RegexWizard.java
private void doLoad() { JFileChooser fileChooser = new JFileChooser(voConfigHelper.getFolderPath()); if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); if (file.exists()) { configField.setText(file.getPath()); compileResultsField.setText(""); VideoAnalysisConfig voConfig = voConfigHelper.loadConfigFile(file.getAbsolutePath()); // get VideoAnalysisConfig type and setText of fields if (voConfig != null) { signalStopCellEditing(); this.videoConfig = voConfig; regexRequestField.setText(voConfig.getRegex()); regexResponseField.setText(voConfig.getResponseRegex()); regexHeaderField.setText(voConfig.getHeaderRegex()); String[] result = extractResult(voConfig); displayResult(result);/*from www .j av a 2s . c o m*/ } else { JOptionPane.showMessageDialog(this, "Failed to load the configuration file.", "Failure", JOptionPane.ERROR_MESSAGE); } } } }
From source file:it.unibas.spicygui.controllo.provider.composition.MyPopupProviderWidgetChainComposition.java
private void loadDataSource() { JFileChooser chooser = vista.getFileChooserApriXSD(); try {/* w w w . java2 s.co m*/ LayerWidget mainLayer = (LayerWidget) chainWidget.getParentWidget(); CaratteristicheWidgetChainComposition caratteristicheWidgetChainComposition = (CaratteristicheWidgetChainComposition) mainLayer .getChildConstraint(chainWidget); ICompositionWidget sourceWidget = caratteristicheWidgetChainComposition.getSourceScenario(); AbstractCaratteristicheWidgetComposition caratteristicheSourceWidget = (AbstractCaratteristicheWidgetComposition) mainLayer .getChildConstraint((Widget) sourceWidget); MappingTask mappingTaskSource = caratteristicheSourceWidget.getMutableMappingTask().getMappingTask(); IDataSourceProxy source = mappingTaskSource.getTargetProxy(); source.getInstances(); int returnVal = chooser.showOpenDialog(WindowManager.getDefault().getMainWindow()); if (returnVal == JFileChooser.APPROVE_OPTION) { //giannisk Scenarios.getNextFreeNumber(); IDataSourceProxy target = loadXMLDataSource(chooser.getSelectedFile().getAbsolutePath()); MappingTask mappingTask = new MappingTask(source, target, SpicyEngineConstants.LINES_BASED_MAPPING_TASK); caratteristicheWidgetChainComposition.getMutableMappingTask().setMappingTask(mappingTask); Scenario scenario = Utility.gestioneScenario(mappingTask, modello, actionProjectTree); chainWidget.changeImage(scenario.getImageNumber()); chainWidget.revalidate(); } } catch (DAOException ex) { logger.error(ex); DialogDisplayer.getDefault() .notify(new NotifyDescriptor.Message( NbBundle.getMessage(Costanti.class, Costanti.NEW_ERROR) + " : " + ex.getMessage(), DialogDescriptor.ERROR_MESSAGE)); } catch (IllegalDataSourceException ex) { logger.error(ex); DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( NbBundle.getMessage(Costanti.class, Costanti.NO_INSTANCES_FOR_COMPOSITION))); } }