List of usage examples for javax.swing JTextPane setCaretPosition
@BeanProperty(bound = false, description = "the caret position") public void setCaretPosition(int position)
TextComponent
. From source file:de.huxhorn.lilith.swing.LicenseAgreementDialog.java
private void initUI() { JPanel content = new JPanel(); content.setLayout(new BorderLayout()); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); JTextPane licenseTextPane = new JTextPane(); HTMLEditorKit htmlEditorKit = new HTMLEditorKit(); String licenseText = null;/* ww w . ja v a 2s .c o m*/ InputStream licenseStream = LicenseAgreementDialog.class.getResourceAsStream("/licenses/license.html"); if (licenseStream != null) { try { licenseText = IOUtils.toString(licenseStream, StandardCharsets.UTF_8); } catch (IOException ex) { if (logger.isErrorEnabled()) logger.error("Exception while loading license!", ex); IOUtilities.interruptIfNecessary(ex); } finally { IOUtilities.closeQuietly(licenseStream); } } if (licenseText == null) { if (logger.isErrorEnabled()) logger.error("Couldn't find license text! Exiting!"); System.exit(-1); } licenseTextPane.setEditorKit(htmlEditorKit); licenseTextPane.setEditable(false); licenseTextPane.setText(licenseText); JScrollPane licenseScrollPane = new JScrollPane(licenseTextPane); licenseScrollPane.setPreferredSize(new Dimension(640, 480)); content.add(licenseScrollPane, BorderLayout.CENTER); content.add(buttonPanel, BorderLayout.SOUTH); AcceptAction acceptAction = new AcceptAction(); DeclineAction declineAction = new DeclineAction(); JButton acceptButton = new JButton(acceptAction); JButton declineButton = new JButton(declineAction); buttonPanel.add(acceptButton); buttonPanel.add(declineButton); setContentPane(content); licenseTextPane.setCaretPosition(0); declineButton.requestFocusInWindow(); }
From source file:edu.ku.brc.specify.tasks.SystemSetupTask.java
/** * /* w w w . ja v a 2 s . c o m*/ */ private void synonymCleanup() { JTextPane tp = new JTextPane(); JScrollPane js = new JScrollPane(); js.getViewport().add(tp); String text = ""; try { String template = "synonym_cleanup_%s.html"; String fileName = String.format(template, Locale.getDefault().getLanguage()); File file = XMLHelper.getConfigDir(fileName); if (!file.exists()) { fileName = String.format(template, "en"); file = XMLHelper.getConfigDir(fileName); } text = FileUtils.readFileToString(file); } catch (Exception ex) { ex.printStackTrace(); } JPanel p = new JPanel(new BorderLayout()); p.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8)); p.add(js, BorderLayout.CENTER); tp.setContentType("text/html"); tp.setText(text); tp.setCaretPosition(0); tp.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 18)); CustomDialog dlg = new CustomDialog((Frame) getTopWindow(), getI18nRS("SYN_CLEANUP"), true, CustomDialog.OKCANCELAPPLY, p); dlg.setOkLabel(getI18nRS("SYN_CLEANUP")); dlg.setCancelLabel(getI18nRS("Report")); dlg.setApplyLabel(getResourceString("CANCEL")); dlg.setCloseOnApplyClk(true); dlg.createUI(); dlg.setSize(600, 450); UIHelper.centerAndShow(dlg); if (dlg.getBtnPressed() == CustomDialog.OK_BTN || dlg.getBtnPressed() == CustomDialog.CANCEL_BTN) { boolean doCleanup = dlg.getBtnPressed() == CustomDialog.OK_BTN; SynonymCleanup synonymCleanup = new SynonymCleanup(doCleanup); synonymCleanup.execute(); // start the background task } }
From source file:org.processmining.analysis.performance.fsmevaluator.FSMEvaluationAnalysisUI.java
public JScrollPane getStringBuffer() { JTextPane myTextPane = new JTextPane(); myTextPane.setContentType("text/html"); myTextPane.setText(sb.toString());/* w w w. ja va 2 s . c om*/ myTextPane.setEditable(false); myTextPane.setCaretPosition(0); JScrollPane scrollPane = new JScrollPane(myTextPane); scrollPane.setBackground(colorBg); return scrollPane; }
From source file:org.quackbot.gui.GUIConsoleAppender.java
/** * Used by Log4j to write something from the LoggingEvent. This simply points to * WriteOutput which writes to the the GUI or to the console * @param event/*w ww.j av a 2s.c o m*/ */ @Override public void append(final ILoggingEvent event) { if (!inited) synchronized (initMessageQueue) { if (!inited) { initMessageQueue.add(event); return; } } //Grab bot info off of MDC final String botId = MDC.get("pircbotx.id"); final String botServer = MDC.get("pircbotx.server"); final String botPort = MDC.get("pircbotx.port"); SwingUtilities.invokeLater(new Runnable() { public void run() { try { //Figure out where this is going JTextPane textPane = (StringUtils.isBlank(botId)) ? gui.CerrorLog : gui.BerrorLog; JScrollPane scrollPane = (StringUtils.isBlank(botId)) ? gui.CerrorScroll : gui.BerrorScroll; //Configure stle StyledDocument doc = textPane.getStyledDocument(); Style msgStyle = event.getLevel().isGreaterOrEqual(Level.WARN) ? doc.getStyle("Error") : doc.getStyle("Normal"); doc.insertString(doc.getLength(), "\n", doc.getStyle("Normal")); int prevLength = doc.getLength(); doc.insertString(doc.getLength(), "[" + dateFormatter.format(event.getTimeStamp()) + "] ", doc.getStyle("Normal")); //time //doc.insertString(doc.getLength(), "["+event.getThreadName()+"] ", doc.getStyle("Thread")); //thread name doc.insertString(doc.getLength(), event.getLevel().toString() + " ", doc.getStyle("Level")); //Logging level doc.insertString(doc.getLength(), event.getLoggerName() + " ", doc.getStyle("Class")); if (StringUtils.isNotBlank(botId)) { String port = !botPort.equals("6667") ? ":" + botPort : ""; doc.insertString(doc.getLength(), "<" + botId + ":" + botServer + port + "> ", doc.getStyle("Server")); } doc.insertString(doc.getLength(), messageLayout.doLayout(event).trim(), msgStyle); //Only autoscroll if the scrollbar is at the bottom //JScrollBar scrollBar = scroll.getVerticalScrollBar(); //if (scrollBar.getVisibleAmount() != scrollBar.getMaximum() && scrollBar.getValue() + scrollBar.getVisibleAmount() == scrollBar.getMaximum()) textPane.setCaretPosition(prevLength); } catch (Exception e) { addError("Exception encountered when logging", e); } } }); }
From source file:pl.otros.logview.gui.actions.search.SearchAction.java
private void scrollToSearchResult(ArrayList<String> toHighlight, JTextPane textPane) { if (toHighlight.size() == 0) { return;/*from w ww.ja va 2 s .co m*/ } try { StyledDocument logDetailsDocument = textPane.getStyledDocument(); String text = logDetailsDocument.getText(0, logDetailsDocument.getLength()); String string = toHighlight.get(0); textPane.setCaretPosition(Math.max(text.indexOf(string), 0)); } catch (BadLocationException e) { e.printStackTrace(); } }