Jxbrowser с tinymce и проверкой орфографии

Я использую jxbrowser в приложении Swing в качестве встроенного браузера. Jxbrowser имеет возможность проверки орфографии, которая отлично работает.

Теперь я должен использовать форматированный текстовый редактор, такой как tinyMce, и проверка орфографии не работает с ним.

Как мне сделать так, чтобы проверка орфографии работала с tinyMCe в jxbrowser? Java-класс:

public class SpellCheckerSample {

public static void main(String[] args) throws Exception {
    // Enable heavyweight popup menu for heavyweight (default) BrowserView component.
    JPopupMenu.setDefaultLightWeightPopupEnabled(false);

    Browser browser = new Browser();
    BrowserView view = new BrowserView(browser);

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.add(view, BorderLayout.CENTER);
    frame.setSize(700, 500);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

    BrowserContext context = browser.getContext();
    SpellCheckerService spellCheckerService = context.getSpellCheckerService();
    spellCheckerService.addSpellCheckListener(new SpellCheckListener() {
        @Override
        public void onSpellCheckCompleted(SpellCheckCompletedParams params) {
            String text = params.getText();
            System.out.println(params.getResults().size());
            System.out.println("text = " + text);
            List<SpellCheckResult> mistakes = params.getResults();
            for (SpellCheckResult mistake : mistakes) {
                System.out.println("mistake.getStartIndex() = " + mistake.getStartIndex());
                System.out.println("mistake.getLength() = " + mistake.getLength());
            }
        }
    });
    // Enable SpellChecker service.
    spellCheckerService.setEnabled(true);
    // Configure SpellChecker's language.
    spellCheckerService.setLanguage("en-US");

    browser.setContextMenuHandler(new MyContextMenuHandler(view, browser));
    //browser.loadHTML(loadHtml);

    browser.loadURL("C:\\tiny.html");
}

private static class MyContextMenuHandler implements ContextMenuHandler {

    private final JComponent component;
    private final Browser browser;

    private MyContextMenuHandler(JComponent parentComponent, Browser browser) {
        this.component = parentComponent;
        this.browser = browser;
    }

    public void showContextMenu(final ContextMenuParams params) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                JPopupMenu popupMenu = createPopupMenu(params);
                Point location = params.getLocation();
                popupMenu.show(component, location.x, location.y);
            }
        });
    }

    private JPopupMenu createPopupMenu(final ContextMenuParams params) {
        final JPopupMenu result = new JPopupMenu();
        // Add suggestions menu items.
        List<String> suggestions = params.getDictionarySuggestions();
        for (final String suggestion : suggestions) {
            result.add(createMenuItem(suggestion, new Runnable() {
                public void run() {
                    browser.replaceMisspelledWord(suggestion);
                }
            }));
        }
        if (!suggestions.isEmpty()) {
            // Add the "Add to Dictionary" menu item.
            result.addSeparator();
            result.add(createMenuItem("Add to Dictionary", new Runnable() {
                public void run() {
                    String misspelledWord = params.getMisspelledWord();
                    browser.addWordToSpellCheckerDictionary(misspelledWord);
                }
            }));
        }
        return result;
    }

    private static JMenuItem createMenuItem(String title, final Runnable action) {
        JMenuItem result = new JMenuItem(title);
        result.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                action.run();
            }
        });
        return result;
    }
}

}

крошечный.html:

<!DOCTYPE html>
<html>
<head>
   <script type="text/javascript" src="tinymce/tinymce.min.js"></script>
  <script>tinymce.init({ selector:'textarea' });</script>
</head>
<body>
  <textarea>Test eror</textarea>
</body>
</html>

person marok    schedule 07.07.2016    source источник
comment
Работает ли это в Google Chrome? Я имею в виду, что если это не работает в Google Chrome, то это может быть так, как задумано в Chrome.   -  person Vladimir    schedule 08.07.2016
comment
В Google Chrome это работает точно так же. Решение состоит в том, чтобы включить browser_spellcheck: browser_spellcheck: true,   -  person marok    schedule 11.07.2016


Ответы (1)


Решение состоит в том, чтобы запустить tinyMCe с помощью browser_spellcheck:true.

  <script>tinymce.init({
       selector:'textarea' ,
       browser_spellcheck: true,
       contextmenu: false
    });</script>
person marok    schedule 08.07.2016