List of usage examples for javax.swing JFileChooser OPEN_DIALOG
int OPEN_DIALOG
To view the source code for javax.swing JFileChooser OPEN_DIALOG.
Click Source Link
JFileChooser
supports an "Open" file operation. From source file:com.acmutv.ontoqa.GrammalexMain.java
/** * The app main method, executed when the program is launched. * @param args The command line arguments. * @throws IllegalAccessException /*from w w w. j a va 2 s . co m*/ * @throws InstantiationException */ public static void main(String[] args) throws InstantiationException, IllegalAccessException { //CliService.handleArguments(args); RuntimeManager.registerShutdownHooks(new ShutdownHook()); try { Path path = FileSystems.getDefault().getPath("data/lexicon").toAbsolutePath(); String currentDirectory = path.toString(); final JFileChooser fc = new JFileChooser(currentDirectory); int returnVal = fc.showOpenDialog(null); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); if (returnVal == JFileChooser.OPEN_DIALOG) { File file = fc.getSelectedFile(); System.out.println("File Select: " + file.getName() + "\n\n"); List<LexicalEntry> lEntries = LexiconUsage.getLexicalEntries(file.getAbsolutePath(), "", LexiconFormat.RDFXML); Grammar grammar = SerializeSltag.getAllElementarySltag(lEntries); SerializeSltag.writeGrammarOnFile(grammar, fileJson); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.exit(0); }
From source file:Main.java
public static String browseForFile(Window owner, String file, int selectionMode, String title, FileFilter filter) {//from w w w.ja va 2s. c o m final String curDir = System.getProperty("user.dir"); JFileChooser chooser = new JFileChooser(curDir); chooser.setDialogType(JFileChooser.OPEN_DIALOG); chooser.setFileSelectionMode(selectionMode); chooser.setApproveButtonText("Select"); chooser.setApproveButtonMnemonic('s'); chooser.setDialogTitle(title); if (filter != null) chooser.setFileFilter(filter); if (file != null && !file.isEmpty()) { File curFile = new File(file); chooser.setCurrentDirectory(curFile.getAbsoluteFile().getParentFile()); if (curFile.isDirectory()) { try { chooser.setSelectedFile(curFile.getCanonicalFile()); } catch (IOException ex) { } } else { chooser.setSelectedFile(curFile); } } if (chooser.showOpenDialog(owner) == JFileChooser.APPROVE_OPTION) { String path = chooser.getSelectedFile().getPath(); try { path = new File(path).getCanonicalPath(); } catch (IOException e) { } // make path relative if possible if (path.startsWith(curDir)) { path = "." + path.substring(curDir.length()); } return path; } return null; }
From source file:cool.pandora.modeller.ui.handlers.base.AddDataHandler.java
/** * addData.//from w w w .ja v a2s .c o m */ void addData() { final File selectFile = new File(File.separator + "."); final JFrame frame = new JFrame(); final JFileChooser fc = new JFileChooser(selectFile); fc.setDialogType(JFileChooser.OPEN_DIALOG); fc.setMultiSelectionEnabled(true); fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fc.setDialogTitle("Add File or Directory"); final int option = fc.showOpenDialog(frame); if (option == JFileChooser.APPROVE_OPTION) { final File[] files = fc.getSelectedFiles(); final String message = ApplicationContextUtil.getMessage("bag.message.filesadded"); if (files != null && files.length > 0) { addBagData(files); ApplicationContextUtil.addConsoleMessage(message + " " + getFileNames(files)); } else { final File file = fc.getSelectedFile(); addBagData(file); ApplicationContextUtil.addConsoleMessage(message + " " + file.getAbsolutePath()); } bagView.bagPayloadTreePanel.refresh(bagView.bagPayloadTree); bagView.updateAddData(); } }
From source file:net.sf.jabref.openoffice.AutoDetectPaths.java
private boolean autoDetectPaths() { if (OS.WINDOWS) { List<File> progFiles = findProgramFilesDir(); File sOffice = null;/*from w w w .j a v a2 s . co m*/ List<File> sofficeFiles = new ArrayList<>(); for (File dir : progFiles) { if (fileSearchCancelled) { return false; } sOffice = findFileDir(dir, "soffice.exe"); if (sOffice != null) { sofficeFiles.add(sOffice); } } if (sOffice == null) { JOptionPane.showMessageDialog(parent, Localization.lang( "Unable to autodetect OpenOffice/LibreOffice installation. Please choose the installation directory manually."), Localization.lang("Could not find OpenOffice/LibreOffice installation"), JOptionPane.INFORMATION_MESSAGE); JFileChooser jfc = new JFileChooser(new File("C:\\")); jfc.setDialogType(JFileChooser.OPEN_DIALOG); jfc.setFileFilter(new javax.swing.filechooser.FileFilter() { @Override public boolean accept(File file) { return file.isDirectory(); } @Override public String getDescription() { return Localization.lang("Directories"); } }); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jfc.showOpenDialog(parent); if (jfc.getSelectedFile() != null) { sOffice = jfc.getSelectedFile(); } } if (sOffice == null) { return false; } if (sofficeFiles.size() > 1) { // More than one file found DefaultListModel<File> mod = new DefaultListModel<>(); for (File tmpfile : sofficeFiles) { mod.addElement(tmpfile); } JList<File> fileList = new JList<>(mod); fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); fileList.setSelectedIndex(0); FormBuilder b = FormBuilder.create() .layout(new FormLayout("left:pref", "pref, 2dlu, pref, 4dlu, pref")); b.add(Localization.lang("Found more than one OpenOffice/LibreOffice executable.")).xy(1, 1); b.add(Localization.lang("Please choose which one to connect to:")).xy(1, 3); b.add(fileList).xy(1, 5); int answer = JOptionPane.showConfirmDialog(null, b.getPanel(), Localization.lang("Choose OpenOffice/LibreOffice executable"), JOptionPane.OK_CANCEL_OPTION); if (answer == JOptionPane.CANCEL_OPTION) { return false; } else { sOffice = fileList.getSelectedValue(); } } else { sOffice = sofficeFiles.get(0); } return setupPreferencesForOO(sOffice.getParentFile(), sOffice, "soffice.exe"); } else if (OS.OS_X) { File rootDir = new File("/Applications"); File[] files = rootDir.listFiles(); if (files != null) { for (File file : files) { if (file.isDirectory() && ("OpenOffice.org.app".equals(file.getName()) || "LibreOffice.app".equals(file.getName()))) { rootDir = file; break; } } } File sOffice = findFileDir(rootDir, SOFFICE_BIN); if (fileSearchCancelled) { return false; } if (sOffice == null) { return false; } else { return setupPreferencesForOO(rootDir, sOffice, SOFFICE_BIN); } } else { // Linux: String usrRoot = "/usr/lib"; File inUsr = findFileDir(new File(usrRoot), SOFFICE); if (fileSearchCancelled) { return false; } if (inUsr == null) { inUsr = findFileDir(new File("/usr/lib64"), SOFFICE); if (inUsr != null) { usrRoot = "/usr/lib64"; } } if (fileSearchCancelled) { return false; } File inOpt = findFileDir(new File("/opt"), SOFFICE); if (fileSearchCancelled) { return false; } if ((inUsr != null) && (inOpt == null)) { return setupPreferencesForOO(usrRoot, inUsr, SOFFICE_BIN); } else if (inOpt != null) { if (inUsr == null) { return setupPreferencesForOO("/opt", inOpt, SOFFICE_BIN); } else { // Found both JRadioButton optRB = new JRadioButton(inOpt.getPath(), true); JRadioButton usrRB = new JRadioButton(inUsr.getPath(), false); ButtonGroup bg = new ButtonGroup(); bg.add(optRB); bg.add(usrRB); FormBuilder b = FormBuilder.create() .layout(new FormLayout("left:pref", "pref, 2dlu, pref, 2dlu, pref ")); b.add(Localization.lang( "Found more than one OpenOffice/LibreOffice executable. Please choose which one to connect to:")) .xy(1, 1); b.add(optRB).xy(1, 3); b.add(usrRB).xy(1, 5); int answer = JOptionPane.showConfirmDialog(null, b.getPanel(), Localization.lang("Choose OpenOffice/LibreOffice executable"), JOptionPane.OK_CANCEL_OPTION); if (answer == JOptionPane.CANCEL_OPTION) { return false; } if (optRB.isSelected()) { return setupPreferencesForOO("/opt", inOpt, SOFFICE_BIN); } else { return setupPreferencesForOO(usrRoot, inUsr, SOFFICE_BIN); } } } } return false; }
From source file:net.sf.jabref.gui.preftabs.PreferencesDialog.java
public PreferencesDialog(JabRefFrame parent) { super(parent, Localization.lang("JabRef preferences"), false); JabRefPreferences prefs = JabRefPreferences.getInstance(); frame = parent;/*w ww . j a v a2 s . c o m*/ main = new JPanel(); JPanel mainPanel = new JPanel(); JPanel lower = new JPanel(); getContentPane().setLayout(new BorderLayout()); getContentPane().add(mainPanel, BorderLayout.CENTER); getContentPane().add(lower, BorderLayout.SOUTH); final CardLayout cardLayout = new CardLayout(); main.setLayout(cardLayout); List<PrefsTab> tabs = new ArrayList<>(); tabs.add(new GeneralTab(prefs)); tabs.add(new NetworkTab(prefs)); tabs.add(new FileTab(frame, prefs)); tabs.add(new FileSortTab(prefs)); tabs.add(new EntryEditorPrefsTab(frame, prefs)); tabs.add(new GroupsPrefsTab(prefs)); tabs.add(new AppearancePrefsTab(prefs)); tabs.add(new ExternalTab(frame, this, prefs)); tabs.add(new TablePrefsTab(prefs)); tabs.add(new TableColumnsTab(prefs, parent)); tabs.add(new LabelPatternPrefTab(prefs, parent.getCurrentBasePanel())); tabs.add(new PreviewPrefsTab(prefs)); tabs.add(new NameFormatterTab(prefs)); tabs.add(new ImportSettingsTab(prefs)); tabs.add(new XmpPrefsTab(prefs)); tabs.add(new AdvancedTab(prefs)); // add all tabs tabs.forEach(tab -> main.add((Component) tab, tab.getTabName())); mainPanel.setBorder(BorderFactory.createEtchedBorder()); String[] tabNames = tabs.stream().map(PrefsTab::getTabName).toArray(String[]::new); JList<String> chooser = new JList<>(tabNames); chooser.setBorder(BorderFactory.createEtchedBorder()); // Set a prototype value to control the width of the list: chooser.setPrototypeCellValue("This should be wide enough"); chooser.setSelectedIndex(0); chooser.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // Add the selection listener that will show the correct panel when // selection changes: chooser.addListSelectionListener(e -> { if (e.getValueIsAdjusting()) { return; } String o = chooser.getSelectedValue(); cardLayout.show(main, o); }); JPanel buttons = new JPanel(); buttons.setLayout(new GridLayout(4, 1)); buttons.add(importPreferences, 0); buttons.add(exportPreferences, 1); buttons.add(showPreferences, 2); buttons.add(resetPreferences, 3); JPanel westPanel = new JPanel(); westPanel.setLayout(new BorderLayout()); westPanel.add(chooser, BorderLayout.CENTER); westPanel.add(buttons, BorderLayout.SOUTH); mainPanel.setLayout(new BorderLayout()); mainPanel.add(main, BorderLayout.CENTER); mainPanel.add(westPanel, BorderLayout.WEST); JButton ok = new JButton(Localization.lang("OK")); JButton cancel = new JButton(Localization.lang("Cancel")); ok.addActionListener(new OkAction()); CancelAction cancelAction = new CancelAction(); cancel.addActionListener(cancelAction); lower.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); ButtonBarBuilder buttonBarBuilder = new ButtonBarBuilder(lower); buttonBarBuilder.addGlue(); buttonBarBuilder.addButton(ok); buttonBarBuilder.addButton(cancel); buttonBarBuilder.addGlue(); // Key bindings: KeyBinder.bindCloseDialogKeyToCancelAction(this.getRootPane(), cancelAction); // Import and export actions: exportPreferences.setToolTipText(Localization.lang("Export preferences to file")); exportPreferences.addActionListener(e -> { String filename = FileDialogs.getNewFile(frame, new File(System.getProperty("user.home")), Collections.singletonList(".xml"), JFileChooser.SAVE_DIALOG, false); if (filename == null) { return; } File file = new File(filename); if (!file.exists() || (JOptionPane.showConfirmDialog(PreferencesDialog.this, Localization.lang("'%0' exists. Overwrite file?", file.getName()), Localization.lang("Export preferences"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION)) { try { prefs.exportPreferences(filename); } catch (JabRefException ex) { LOGGER.warn(ex.getMessage(), ex); JOptionPane.showMessageDialog(PreferencesDialog.this, ex.getLocalizedMessage(), Localization.lang("Export preferences"), JOptionPane.ERROR_MESSAGE); } } }); importPreferences.setToolTipText(Localization.lang("Import preferences from file")); importPreferences.addActionListener(e -> { String filename = FileDialogs.getNewFile(frame, new File(System.getProperty("user.home")), Collections.singletonList(".xml"), JFileChooser.OPEN_DIALOG, false); if (filename != null) { try { prefs.importPreferences(filename); updateAfterPreferenceChanges(); JOptionPane.showMessageDialog(PreferencesDialog.this, Localization.lang("You must restart JabRef for this to come into effect."), Localization.lang("Import preferences"), JOptionPane.WARNING_MESSAGE); } catch (JabRefException ex) { LOGGER.warn(ex.getMessage(), ex); JOptionPane.showMessageDialog(PreferencesDialog.this, ex.getLocalizedMessage(), Localization.lang("Import preferences"), JOptionPane.ERROR_MESSAGE); } } }); showPreferences.addActionListener( e -> new PreferencesFilterDialog(new JabRefPreferencesFilter(Globals.prefs), frame) .setVisible(true)); resetPreferences.addActionListener(e -> { if (JOptionPane.showConfirmDialog(PreferencesDialog.this, Localization.lang("Are you sure you want to reset all settings to default values?"), Localization.lang("Reset preferences"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) { try { prefs.clear(); JOptionPane.showMessageDialog(PreferencesDialog.this, Localization.lang("You must restart JabRef for this to come into effect."), Localization.lang("Reset preferences"), JOptionPane.WARNING_MESSAGE); } catch (BackingStoreException ex) { LOGGER.warn(ex.getMessage(), ex); JOptionPane.showMessageDialog(PreferencesDialog.this, ex.getLocalizedMessage(), Localization.lang("Reset preferences"), JOptionPane.ERROR_MESSAGE); } updateAfterPreferenceChanges(); } }); setValues(); pack(); }
From source file:net.sf.jabref.external.ExternalFilePanel.java
public void browseFile(final String fieldName, final FieldEditor editor) { String[] dirs = metaData.getFileDirectory(fieldName); String directory = null;/*www . j a v a 2 s .com*/ if (dirs.length > 0) { directory = dirs[0]; // Default to the first directory in the list } String dir = editor.getText(); String retVal; if ((directory == null) || !new File(dir).isAbsolute()) { if (directory != null) { dir = directory; } else { dir = Globals.prefs.get(fieldName + Globals.FILETYPE_PREFS_EXT, ""); } } String chosenFile = FileDialogs.getNewFile(frame, new File(dir), '.' + fieldName, JFileChooser.OPEN_DIALOG, false); if (chosenFile != null) { File newFile = new File(chosenFile); String position = newFile.getParent(); if ((directory != null) && position.startsWith(directory)) { // Construct path relative to pdf base dir String relPath = position.substring(directory.length(), position.length()) + File.separator + newFile.getName(); // Remove leading path separator if (relPath.startsWith(File.separator)) { relPath = relPath.substring(File.separator.length(), relPath.length()); // Set relative path as field value } retVal = relPath; } else { retVal = newFile.getPath(); } editor.setText(retVal); Globals.prefs.put(fieldName + Globals.FILETYPE_PREFS_EXT, newFile.getPath()); } }
From source file:cn.labthink.ReadAccess060.java
private void jButton_OpenfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_OpenfileActionPerformed //filter//from www . j a va2 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(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 ww . j a v a 2s . c o 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(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:net.sf.jabref.gui.journals.ManageJournalsPanel.java
public ManageJournalsPanel(final JabRefFrame frame) { this.frame = frame; personalFile.setEditable(false);/*from ww w . ja v a2s. c o m*/ ButtonGroup group = new ButtonGroup(); group.add(newFile); group.add(oldFile); addExtPan.setLayout(new BorderLayout()); JButton addExt = new JButton(IconTheme.JabRefIcon.ADD.getIcon()); addExtPan.add(addExt, BorderLayout.EAST); addExtPan.setToolTipText(Localization.lang("Add")); FormLayout layout = new FormLayout("1dlu, 8dlu, left:pref, 4dlu, fill:200dlu:grow, 4dlu, fill:pref", "pref, pref, pref, 20dlu, 20dlu, fill:200dlu, 4dlu, pref"); FormBuilder builder = FormBuilder.create().layout(layout); builder.addSeparator(Localization.lang("Built-in journal list")).xyw(2, 1, 6); JLabel description = new JLabel( "<HTML>" + Localization.lang("JabRef includes a built-in list of journal abbreviations.") + "<br>" + Localization.lang( "You can add additional journal names by setting up a personal journal list,<br>as " + "well as linking to external journal lists.") + "</HTML>"); description.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0)); builder.add(description).xyw(2, 2, 6); JButton viewBuiltin = new JButton(Localization.lang("View")); builder.add(viewBuiltin).xy(7, 2); builder.addSeparator(Localization.lang("Personal journal list")).xyw(2, 3, 6); builder.add(newFile).xy(3, 4); builder.add(newNameTf).xy(5, 4); JButton browseNew = new JButton(Localization.lang("Browse")); builder.add(browseNew).xy(7, 4); builder.add(oldFile).xy(3, 5); builder.add(personalFile).xy(5, 5); JButton browseOld = new JButton(Localization.lang("Browse")); builder.add(browseOld).xy(7, 5); userPanel.setLayout(new BorderLayout()); builder.add(userPanel).xyw(2, 6, 4); ButtonStackBuilder butBul = new ButtonStackBuilder(); butBul.addButton(add); butBul.addButton(remove); butBul.addGlue(); builder.add(butBul.getPanel()).xy(7, 6); builder.addSeparator(Localization.lang("External files")).xyw(2, 8, 6); externalFilesPanel.setLayout(new BorderLayout()); setLayout(new BorderLayout()); builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); add(builder.getPanel(), BorderLayout.NORTH); add(externalFilesPanel, BorderLayout.CENTER); ButtonBarBuilder bb = new ButtonBarBuilder(); bb.addGlue(); JButton ok = new JButton(Localization.lang("OK")); bb.addButton(ok); JButton cancel = new JButton(Localization.lang("Cancel")); bb.addButton(cancel); bb.addUnrelatedGap(); JButton help = new HelpAction(HelpFile.JOURNAL_ABBREV).getHelpButton(); bb.addButton(help); bb.addGlue(); bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); dialog = new JDialog(frame, Localization.lang("Journal abbreviations"), false); dialog.getContentPane().add(this, BorderLayout.CENTER); dialog.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH); // Set up panel for editing a single journal, to be used in a dialog box: FormLayout layout2 = new FormLayout("right:pref, 4dlu, fill:180dlu", "p, 2dlu, p"); FormBuilder builder2 = FormBuilder.create().layout(layout2); builder2.add(Localization.lang("Journal name")).xy(1, 1); builder2.add(nameTf).xy(3, 1); builder2.add(Localization.lang("ISO abbreviation")).xy(1, 3); builder2.add(abbrTf).xy(3, 3); journalEditPanel = builder2.getPanel(); viewBuiltin.addActionListener(e -> { JTable table = new JTable(JournalAbbreviationsUtil.getTableModel(Globals.journalAbbreviationLoader .getRepository(JournalAbbreviationPreferences.fromPreferences(Globals.prefs)) .getAbbreviations())); JScrollPane pane = new JScrollPane(table); JOptionPane.showMessageDialog(null, pane, Localization.lang("Journal list preview"), JOptionPane.INFORMATION_MESSAGE); }); browseNew.addActionListener(e -> { Path old = null; if (!newNameTf.getText().isEmpty()) { old = Paths.get(newNameTf.getText()); } String name = FileDialogs.getNewFile(frame, old.toFile(), null, JFileChooser.SAVE_DIALOG, false); if (name != null) { newNameTf.setText(name); newFile.setSelected(true); } }); browseOld.addActionListener(e -> { Path old = null; if (!personalFile.getText().isEmpty()) { old = Paths.get(personalFile.getText()); } String name = FileDialogs.getNewFile(frame, old.toFile(), null, JFileChooser.OPEN_DIALOG, false); if (name != null) { personalFile.setText(name); oldFile.setSelected(true); oldFile.setEnabled(true); setupUserTable(); } }); ok.addActionListener(e -> { if (readyToClose()) { storeSettings(); dialog.dispose(); } }); Action cancelAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } }; cancel.addActionListener(cancelAction); add.addActionListener(tableModel); remove.addActionListener(tableModel); addExt.addActionListener(e -> { externals.add(new ExternalFileEntry()); buildExternalsPanel(); }); // Key bindings: ActionMap am = getActionMap(); InputMap im = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close"); am.put("close", cancelAction); int xSize = getPreferredSize().width; dialog.setSize(xSize + 10, 700); }
From source file:ch.admin.hermes.etl.load.HermesETLApplication.java
/** * FileOpen Dialog/*from w ww . j a va2s . c o m*/ * @param title * @param name * @param ext * @return */ private static String getFile(final String title, final String[] name, final String[] ext) { // User Chooses a Path and Name for the html Output File JFileChooser fc = new JFileChooser("."); fc.setDialogType(JFileChooser.OPEN_DIALOG); fc.setDialogTitle(title); fc.setFileFilter(new FileFilter() { public String getDescription() { StringBuffer str = new StringBuffer(); for (String n : name) str.append(n + ""); return (str.toString()); } public boolean accept(File f) { for (String e : ext) if (f.isDirectory() || f.getName().toLowerCase().endsWith(e)) return (true); return false; } }); int state = fc.showOpenDialog(null); if (state == JFileChooser.APPROVE_OPTION) return (fc.getSelectedFile().getPath()); return (null); }