Example usage for javax.swing JEditorPane setCaretPosition

List of usage examples for javax.swing JEditorPane setCaretPosition

Introduction

In this page you can find the example usage for javax.swing JEditorPane setCaretPosition.

Prototype

@BeanProperty(bound = false, description = "the caret position")
public void setCaretPosition(int position) 

Source Link

Document

Sets the position of the text insertion caret for the TextComponent.

Usage

From source file:eu.apenet.dpt.standalone.gui.APETabbedPane.java

public JComponent createMsgEditionTree(String msg) {
    JEditorPane waitMessagePane = new JEditorPane();
    waitMessagePane.setEditable(false);/*  w w  w  . jav a2s  .c  o  m*/
    waitMessagePane.setContentType("text/plain");
    waitMessagePane.setText(msg);
    waitMessagePane.setCaretPosition(0);
    return waitMessagePane;
}

From source file:com.enderville.enderinstaller.ui.Installer.java

private void loadModDescription(String modName) {
    JPanel p = getModDescriptionPane();
    p.removeAll();//from  w  ww.j  a v  a2 s.c o  m
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));

    final String extras = InstallerConfig.getExtraModsFolder();
    final String modFolderName = FilenameUtils.concat(extras, modName);
    File modFolder = new File(modFolderName);
    if (!modFolder.exists()) {
        LOGGER.error("Mod folder for " + modName + " does not exist.");
    }
    File descrFile = new File(FilenameUtils.concat(modFolderName, "description.txt"));
    File imgFile = new File(FilenameUtils.concat(modFolderName, "image.png"));
    if (!descrFile.exists() && !imgFile.exists()) {
        p.add(new JLabel("<html>No description for:<br>" + modName + "</html>"));
    } else {
        if (imgFile.exists()) {
            try {
                JLabel label = new JLabel();
                BufferedImage img = ImageIO.read(imgFile);
                label.setIcon(new ImageIcon(img));
                p.add(label);
            } catch (IOException e) {
                LOGGER.error("Error reading image file: " + imgFile.getPath(), e);
            }
        }
        if (descrFile.exists()) {
            StringBuilder buffer = new StringBuilder();
            try {
                BufferedReader r = new BufferedReader(new FileReader(descrFile));
                String l = null;
                while ((l = r.readLine()) != null) {
                    buffer.append(l + "\n");
                }
                r.close();
                JEditorPane area = new JEditorPane();
                area.setContentType("text/html");
                area.setText(buffer.toString());
                area.setEditable(false);
                area.addHyperlinkListener(this);
                area.setCaretPosition(0);
                p.add(new JScrollPane(area));
            } catch (IOException e) {
                LOGGER.error("Error reading description file: " + descrFile.getPath(), e);
            }
        }
    }

    p.validate();
    p.repaint();
}

From source file:org.apache.tika.gui.TikaGUI.java

private void handleError(String name, Throwable t) {
    StringWriter writer = new StringWriter();
    writer.append("Apache Tika was unable to parse the document\n");
    writer.append("at " + name + ".\n\n");
    writer.append("The full exception stack trace is included below:\n\n");
    t.printStackTrace(new PrintWriter(writer));

    JEditorPane editor = new JEditorPane("text/plain", writer.toString());
    editor.setEditable(false);//  ww  w.  ja va2 s.c o  m
    editor.setBackground(Color.WHITE);
    editor.setCaretPosition(0);
    editor.setPreferredSize(new Dimension(600, 400));

    JDialog dialog = new JDialog(this, "Apache Tika error");
    dialog.add(new JScrollPane(editor));
    dialog.pack();
    dialog.setVisible(true);
}

From source file:org.apache.tika.gui.TikaGUI.java

public void hyperlinkUpdate(HyperlinkEvent e) {
    if (e.getEventType() == EventType.ACTIVATED) {
        try {/*from ww w .j a v  a  2  s  . com*/
            URL url = e.getURL();
            try (InputStream stream = url.openStream()) {
                JEditorPane editor = new JEditorPane("text/plain", IOUtils.toString(stream, UTF_8));
                editor.setEditable(false);
                editor.setBackground(Color.WHITE);
                editor.setCaretPosition(0);
                editor.setPreferredSize(new Dimension(600, 400));

                String name = url.toString();
                name = name.substring(name.lastIndexOf('/') + 1);

                JDialog dialog = new JDialog(this, "Apache Tika: " + name);
                dialog.add(new JScrollPane(editor));
                dialog.pack();
                dialog.setVisible(true);
            }
        } catch (IOException exception) {
            exception.printStackTrace();
        }
    }
}

From source file:org.apache.tika.gui.TikaGUI.java

private void setText(JEditorPane editor, String text) {
    editor.setText(text);
    editor.setCaretPosition(0);
}

From source file:org.formic.wizard.step.gui.TemplateStep.java

/**
 * {@inheritDoc}/*from w w  w . j a  va2  s .c o m*/
 * @see org.formic.wizard.WizardStep#displayed()
 */
public void displayed() {
    if (content instanceof JEditorPane) {
        JEditorPane editor = (JEditorPane) content;
        editor.setText(action.processTemplate(html));
        editor.setCaretPosition(0);
    } else {
        JTextArea area = (JTextArea) content;
        area.setText(action.processTemplate(text));
        area.setCaretPosition(0);
    }
}

From source file:org.geworkbench.components.lincs.LincsInterface.java

private void viewLicense_actionPerformed(String FileName) {

    getLicenseFromFile(FileName);/*w ww.  j a v a 2 s  .  c o m*/
    JDialog licenseDialog = new JDialog();
    final JEditorPane jEditorPane = new JEditorPane("text/html", "");
    jEditorPane.getDocument().putProperty("IgnoreCharsetDirective", Boolean.TRUE);
    jEditorPane.setText(licenseContent);
    if (jEditorPane.getCaretPosition() > 1) {
        jEditorPane.setCaretPosition(1);
    }
    JScrollPane scrollPane = new JScrollPane(jEditorPane);
    licenseDialog.setTitle("Lincs Interface License");
    licenseDialog.setContentPane(scrollPane);
    licenseDialog.setSize(400, 300);
    licenseDialog.setLocationRelativeTo(this);
    licenseDialog.setVisible(true);
}

From source file:org.geworkbench.engine.ccm.ComponentConfigurationManagerWindow.java

/**
 * Display a dialog box with a components license in it.
 * //from w  w  w  .  j a v  a  2 s. c  o  m
 * @param ActionEvent
 * @return void
 */
private void viewLicense_actionPerformed(ActionEvent e) {

    int[] selectedRow = table.getSelectedRows();

    String license = "Select a component in order to view its license.";
    String componentName = null;
    if (selectedRow != null && selectedRow.length > 0 && selectedRow[0] >= 0) {

        int modelRow = table.convertRowIndexToModel(selectedRow[0]);
        license = (String) ccmTableModel.getModelValueAt(modelRow, CCMTableModel.LICENSE_INDEX);
        componentName = (String) ccmTableModel.getModelValueAt(modelRow, CCMTableModel.NAME_INDEX);
    }

    JDialog licenseDialog = new JDialog();
    final JEditorPane jEditorPane = new JEditorPane("text/html", "");
    jEditorPane.getDocument().putProperty("IgnoreCharsetDirective", Boolean.TRUE);
    jEditorPane.setText(license);
    if (jEditorPane.getCaretPosition() > 1) {
        jEditorPane.setCaretPosition(1);
    }
    JScrollPane scrollPane = new JScrollPane(jEditorPane);
    licenseDialog.setTitle(componentName + " License");
    licenseDialog.setContentPane(scrollPane);
    licenseDialog.setSize(400, 300);
    licenseDialog.setLocationRelativeTo(frame);
    licenseDialog.setVisible(true);
}

From source file:org.geworkbench.engine.ccm.ComponentConfigurationManagerWindow2.java

/**
 * Display a dialog box with a components license in it.
 * /*from w  w  w .j  av  a  2s  .  com*/
 * @param ActionEvent
 * @return void
 */
private void viewLicense_actionPerformed(ActionEvent e) {

    int[] selectedRow = table.getSelectedRows();

    String license = "Select a component in order to view its license.";
    String componentName = null;
    if (selectedRow != null && selectedRow.length > 0 && selectedRow[0] >= 0) {

        int modelRow = table.convertRowIndexToModel(selectedRow[0]);
        license = (String) ccmTableModel.getModelValueAt(modelRow, CCMTableModel2.LICENSE_INDEX);
        componentName = (String) ccmTableModel.getModelValueAt(modelRow, CCMTableModel2.NAME_INDEX);
    }

    JDialog licenseDialog = new JDialog();
    final JEditorPane jEditorPane = new JEditorPane("text/html", "");
    jEditorPane.getDocument().putProperty("IgnoreCharsetDirective", Boolean.TRUE);
    jEditorPane.setText(license);
    if (jEditorPane.getCaretPosition() > 1) {
        jEditorPane.setCaretPosition(1);
    }
    JScrollPane scrollPane = new JScrollPane(jEditorPane);
    licenseDialog.setTitle(componentName + " License");
    licenseDialog.setContentPane(scrollPane);
    licenseDialog.setSize(400, 300);
    licenseDialog.setLocationRelativeTo(frame);
    licenseDialog.setVisible(true);
}