List of usage examples for javax.swing JTextPane getPreferredSize
public Dimension getPreferredSize()
JEditorPane
. From source file:org.languagetool.gui.Tools.java
static void showRuleInfoDialog(Component parent, String title, String message, Rule rule, URL matchUrl, ResourceBundle messages, String lang) { int dialogWidth = 320; JTextPane textPane = new JTextPane(); textPane.setEditable(false);/* w w w . j a va2 s . c o m*/ textPane.setContentType("text/html"); textPane.setBorder(BorderFactory.createEmptyBorder()); textPane.setOpaque(false); textPane.setBackground(new Color(0, 0, 0, 0)); Tools.addHyperlinkListener(textPane); textPane.setSize(dialogWidth, Short.MAX_VALUE); String messageWithBold = message.replaceAll("<suggestion>", "<b>").replaceAll("</suggestion>", "</b>"); String exampleSentences = getExampleSentences(rule, messages); String url = "http://community.languagetool.org/rule/show/" + encodeUrl(rule) + "?lang=" + lang + "&ref=standalone-gui"; boolean isExternal = rule.getCategory().getLocation() == Category.Location.EXTERNAL; String ruleDetailLink = rule instanceof FalseFriendPatternRule || isExternal ? "" : "<a href='" + url + "'>" + messages.getString("ruleDetailsLink") + "</a>"; textPane.setText("<html>" + messageWithBold + exampleSentences + formatURL(matchUrl) + "<br><br>" + ruleDetailLink + "</html>"); JScrollPane scrollPane = new JScrollPane(textPane); scrollPane.setPreferredSize(new Dimension(dialogWidth, textPane.getPreferredSize().height)); scrollPane.setBorder(BorderFactory.createEmptyBorder()); String cleanTitle = title.replace("<suggestion>", "'").replace("</suggestion>", "'"); JOptionPane.showMessageDialog(parent, scrollPane, cleanTitle, JOptionPane.INFORMATION_MESSAGE); }