List of usage examples for javax.swing JFileChooser requestFocus
public void requestFocus()
Component
gets the input focus. From source file:kenh.xscript.ScriptUtils.java
public static void main(String[] args) { String file = null;// w w w. jav a2 s . c o m for (String arg : args) { if (StringUtils.startsWithAny(StringUtils.lowerCase(arg), "-f:", "-file:")) { file = StringUtils.substringAfter(arg, ":"); } } Element e = null; try { if (StringUtils.isBlank(file)) { JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("xScript"); chooser.setAcceptAllFileFilterUsed(false); chooser.setFileFilter(new FileFilter() { public boolean accept(File f) { if (f.isDirectory()) { return true; } else if (f.isFile() && StringUtils.endsWithIgnoreCase(f.getName(), ".xml")) { return true; } return false; } public String getDescription() { return "xScript (*.xml)"; } }); int returnVal = chooser.showOpenDialog(null); chooser.requestFocus(); if (returnVal == JFileChooser.CANCEL_OPTION) return; File f = chooser.getSelectedFile(); e = getInstance(f, null); } else { e = getInstance(new File(file), null); } //debug(e); //System.out.println("----------------------"); int result = e.invoke(); if (result == Element.EXCEPTION) { Object obj = e.getEnvironment().getVariable(Constant.VARIABLE_EXCEPTION); if (obj != null && obj instanceof Throwable) { System.err.println(); ((Throwable) obj).printStackTrace(); } else { System.err.println(); System.err.println("Unknown EXCEPTION is thrown."); } } } catch (Exception ex) { ex.printStackTrace(); System.err.println(); if (ex instanceof UnsupportedScriptException) { UnsupportedScriptException ex_ = (UnsupportedScriptException) ex; if (ex_.getElement() != null) { debug(ex_.getElement(), System.err); } } } finally { if (e != null) e.getEnvironment().callback(); } }