Search in sources :

Example 76 with JEditorPane

use of javax.swing.JEditorPane in project jdk8u_jdk by JetBrains.

the class LargeQuickDoc method main.

public static void main(String[] args) throws Exception {
    SwingUtilities.invokeAndWait(() -> {
        JFrame f = new JFrame();
        JEditorPane editorPane = new javax.swing.JEditorPane("text/html", "");
        editorPane.setEditorKit(new HTMLEditorKit());
        editorPane.setEditable(false);
        JScrollPane scrollPane = new JScrollPane(editorPane);
        scrollPane.setBorder(null);
        try {
            editorPane.setText(getText());
        } catch (IOException | ArrayIndexOutOfBoundsException e) {
            throw new RuntimeException(e);
        }
        f.getContentPane().add(scrollPane);
        f.setSize(500, 500);
        f.setVisible(true);
    });
}
Also used : JScrollPane(javax.swing.JScrollPane) JFrame(javax.swing.JFrame) JEditorPane(javax.swing.JEditorPane) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) IOException(java.io.IOException)

Example 77 with JEditorPane

use of javax.swing.JEditorPane in project jabref by JabRef.

the class PreviewPanelTransferHandler method createTransferable.

@Override
protected Transferable createTransferable(JComponent component) {
    if (component instanceof JEditorPane) {
        // this method should be called from the preview panel only
        // the default TransferHandler implementation is aware of HTML
        // and returns an appropriate Transferable
        // as textTransferHandler.createTransferable() is not available and
        // I don't know any other method, I do the HTML conversion by hand
        // First, get the HTML of the selected text
        JEditorPane editorPane = (JEditorPane) component;
        StringWriter stringWriter = new StringWriter();
        try {
            editorPane.getEditorKit().write(stringWriter, editorPane.getDocument(), editorPane.getSelectionStart(), editorPane.getSelectionEnd());
        } catch (BadLocationException | IOException e) {
            LOGGER.warn("Cannot write preview", e);
        }
        // Second, return the HTML (and text as fallback)
        return new HtmlTransferable(stringWriter.toString(), editorPane.getSelectedText());
    } else {
        // if not called from the preview panel, return an error string
        return new StringSelection(Localization.lang("Operation not supported"));
    }
}
Also used : StringWriter(java.io.StringWriter) JEditorPane(javax.swing.JEditorPane) IOException(java.io.IOException) BadLocationException(javax.swing.text.BadLocationException) StringSelection(java.awt.datatransfer.StringSelection)

Example 78 with JEditorPane

use of javax.swing.JEditorPane in project jgnash by ccavanaugh.

the class BudgetWizardDialog method initComponents.

private void initComponents() {
    okButton = new JButton(rb.getString("Button.Ok"));
    cancelButton = new JButton(rb.getString("Button.Cancel"));
    budgetPeriodCombo = new JComboBox<>();
    budgetPeriodCombo.setModel(new DefaultComboBoxModel<>(Period.values()));
    budgetPeriodCombo.setSelectedItem(Period.MONTHLY);
    budgetNameField = new JTextField();
    DefaultUnitConverter unitConverter = DefaultUnitConverter.getInstance();
    helpPane = new JEditorPane();
    helpPane.setEditable(false);
    helpPane.setEditorKit(new StyledEditorKit());
    helpPane.setBackground(getBackground());
    helpPane.setText(TextResource.getString("NewBudgetOne.txt"));
    helpPane.setPreferredSize(new Dimension(unitConverter.dialogUnitXAsPixel(DLU_X, helpPane), unitConverter.dialogUnitYAsPixel(DLU_Y, helpPane)));
    roundButton = new JCheckBox(rb.getString("Button.RoundToWhole"));
    okButton.addActionListener(this);
    cancelButton.addActionListener(this);
}
Also used : StyledEditorKit(javax.swing.text.StyledEditorKit) JCheckBox(javax.swing.JCheckBox) JButton(javax.swing.JButton) JEditorPane(javax.swing.JEditorPane) DefaultUnitConverter(com.jgoodies.forms.util.DefaultUnitConverter) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField)

Example 79 with JEditorPane

use of javax.swing.JEditorPane in project jgnash by ccavanaugh.

the class NewFileThree method initComponents.

private void initComponents() {
    addButton = new JButton(rb.getString("Button.Add"));
    addButton.setIcon(IconUtils.getIcon("/jgnash/resource/list-add.png"));
    addButton.setHorizontalTextPosition(SwingConstants.LEADING);
    removeButton = new JButton(rb.getString("Button.Remove"));
    removeButton.setIcon(IconUtils.getIcon("/jgnash/resource/list-remove.png"));
    aJList = new JList<>();
    cJList = new JList<>();
    helpPane = new JEditorPane();
    helpPane.setEditable(false);
    helpPane.setEditorKit(new StyledEditorKit());
    helpPane.setBackground(getBackground());
    helpPane.setText(TextResource.getString("NewFileThree.txt"));
    addButton.addActionListener(this);
    removeButton.addActionListener(this);
}
Also used : StyledEditorKit(javax.swing.text.StyledEditorKit) JButton(javax.swing.JButton) JEditorPane(javax.swing.JEditorPane)

Example 80 with JEditorPane

use of javax.swing.JEditorPane in project tika by apache.

the class TikaGUI method textDialog.

private void textDialog(String title, URL resource) {
    try {
        JDialog dialog = new JDialog(this, title);
        JEditorPane editor = new JEditorPane(resource);
        editor.setContentType("text/html");
        editor.setEditable(false);
        editor.setBackground(Color.WHITE);
        editor.setPreferredSize(new Dimension(400, 250));
        editor.addHyperlinkListener(this);
        dialog.add(editor);
        dialog.pack();
        dialog.setVisible(true);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : JEditorPane(javax.swing.JEditorPane) Dimension(java.awt.Dimension) IOException(java.io.IOException) JDialog(javax.swing.JDialog)

Aggregations

JEditorPane (javax.swing.JEditorPane)130 JScrollPane (javax.swing.JScrollPane)54 Dimension (java.awt.Dimension)34 JPanel (javax.swing.JPanel)34 JButton (javax.swing.JButton)22 JLabel (javax.swing.JLabel)21 BorderLayout (java.awt.BorderLayout)20 IOException (java.io.IOException)16 HyperlinkEvent (javax.swing.event.HyperlinkEvent)16 JFrame (javax.swing.JFrame)15 HyperlinkListener (javax.swing.event.HyperlinkListener)15 JDialog (javax.swing.JDialog)14 GridBagConstraints (java.awt.GridBagConstraints)12 GridBagLayout (java.awt.GridBagLayout)12 URL (java.net.URL)12 ActionEvent (java.awt.event.ActionEvent)11 FlowLayout (java.awt.FlowLayout)10 HTMLEditorKit (javax.swing.text.html.HTMLEditorKit)10 Component (java.awt.Component)9 JSplitPane (javax.swing.JSplitPane)9