List of usage examples for javax.swing JTextPane requestFocusInWindow
public boolean requestFocusInWindow()
Component
gets the input focus. From source file:de.huxhorn.lilith.swing.preferences.PreferencesDialog.java
public void editDetailsFormatter() { Console console = new Console(); File messageViewRoot = applicationPreferences.getDetailsViewRoot(); File messageViewGroovyFile = new File(messageViewRoot, ApplicationPreferences.DETAILS_VIEW_GROOVY_FILENAME); EventWrapper<LoggingEvent> eventWrapper = new EventWrapper<>( new SourceIdentifier("identifier", "secondaryIdentifier"), 17, new LoggingEvent()); console.setVariable("eventWrapper", eventWrapper); console.setCurrentFileChooserDir(messageViewRoot); String text = ""; if (!messageViewGroovyFile.isFile()) { applicationPreferences.initDetailsViewRoot(true); }//from w ww. j a va 2 s . c om if (messageViewGroovyFile.isFile()) { InputStream is; try { is = new FileInputStream(messageViewGroovyFile); List lines = IOUtils.readLines(is, StandardCharsets.UTF_8); boolean isFirst = true; StringBuilder textBuffer = new StringBuilder(); for (Object o : lines) { String s = (String) o; if (isFirst) { isFirst = false; } else { textBuffer.append("\n"); } textBuffer.append(s); } text = textBuffer.toString(); } catch (IOException e) { if (logger.isInfoEnabled()) { logger.info("Exception while reading '" + messageViewGroovyFile.getAbsolutePath() + "'.", e); } } } else { if (logger.isWarnEnabled()) logger.warn("Failed to initialize detailsView file '{}'!", messageViewGroovyFile.getAbsolutePath()); } console.run(); // initializes everything console.setScriptFile(messageViewGroovyFile); JTextPane inputArea = console.getInputArea(); //inputArea.setText(text); Document doc = inputArea.getDocument(); try { doc.remove(0, doc.getLength()); doc.insertString(0, text, null); } catch (BadLocationException e) { if (logger.isWarnEnabled()) logger.warn("Exception while setting source!", e); } console.setDirty(false); inputArea.setCaretPosition(0); inputArea.requestFocusInWindow(); }