javax.swing.text.html.HTMLEditorKit类的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(13.9k)|赞(0)|评价(0)|浏览(167)

本文整理了Java中javax.swing.text.html.HTMLEditorKit类的一些代码示例,展示了HTMLEditorKit类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HTMLEditorKit类的具体详情如下:
包路径:javax.swing.text.html.HTMLEditorKit
类名称:HTMLEditorKit

HTMLEditorKit介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

  1. JTextPane text_panel = new JTextPane();
  2. HTMLEditorKit kit = new HTMLEditorKit();
  3. HTMLDocument doc = new HTMLDocument();
  4. text_panel.setEditorKit(kit);
  5. text_panel.setDocument(doc);
  6. kit.insertHTML(doc, doc.getLength(), "<b>hello", 0, 0, HTML.Tag.B);
  7. kit.insertHTML(doc, doc.getLength(), "<font color='red'><u>world</u></font>", 0, 0, null);

代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin

  1. @NotNull
  2. public static JTextPane createDescriptionPane() {
  3. JTextPane result = new JTextPane();
  4. result.addHyperlinkListener(new BrowserHyperlinkListener());
  5. result.setContentType("text/html");
  6. Font descriptionFont = UIUtil.getLabelFont(UIUtil.FontSize.SMALL);
  7. HTMLEditorKit editorKit = UIUtil.getHTMLEditorKit();
  8. editorKit.getStyleSheet().addRule("body, p {" +
  9. "color:#" + ColorUtil.toHex(UIUtil.getLabelFontColor(UIUtil.FontColor.BRIGHTER)) + ";" +
  10. "font-family:" + descriptionFont.getFamily() + ";" +
  11. "font-size:" + descriptionFont.getSize() + "pt;}");
  12. result.setHighlighter(null);
  13. result.setEditorKit(editorKit);
  14. return result;
  15. }
  16. }

代码示例来源:origin: org.netbeans.api/org-openide-dialogs

  1. public FixedHeightPane () {
  2. super ();
  3. setEditable(false);
  4. HTMLEditorKit htmlkit = new HTMLEditorKit();
  5. StyleSheet css = htmlkit.getStyleSheet();
  6. if (css.getStyleSheets() == null) {
  7. StyleSheet css2 = new StyleSheet();
  8. Font f = new JList().getFont();
  9. int size = f.getSize();
  10. try {
  11. css2.addRule(new StringBuffer("body { font-size: ").append(size) // NOI18N
  12. .append("; font-family: ").append(f.getName()).append("; }").toString()); // NOI18N
  13. css2.addStyleSheet(css);
  14. htmlkit.setStyleSheet(css2);
  15. } catch( RuntimeException ex ) {

代码示例来源:origin: net.imagej/ij

  1. private void init(String message) {
  2. ij.util.Java2.setSystemLookAndFeel();
  3. Container container = getContentPane();
  4. container.setLayout(new BorderLayout());
  5. if (message==null) message = "";
  6. editorPane = new JEditorPane("text/html","");
  7. editorPane.setEditable(false);
  8. HTMLEditorKit kit = new HTMLEditorKit();
  9. editorPane.setEditorKit(kit);
  10. StyleSheet styleSheet = kit.getStyleSheet();
  11. styleSheet.addRule("body{font-family:Verdana,sans-serif; font-size:11.5pt; margin:5px 10px 5px 10px;}"); //top right bottom left
  12. styleSheet.addRule("h1{font-size:18pt;}");
  13. styleSheet.addRule("h2{font-size:15pt;}");
  14. styleSheet.addRule("dl dt{font-face:bold;}");
  15. editorPane.setText(message); //display the html text with the above style
  16. public void actionPerformed(ActionEvent e) {}
  17. JScrollPane scrollPane = new JScrollPane(editorPane);
  18. container.add(scrollPane);
  19. JButton button = new JButton("OK");
  20. button.addActionListener(this);

代码示例来源:origin: tinyMediaManager/tinyMediaManager

  1. private void initComponents() {
  2. setLayout(new FormLayout(new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC, },
  3. new RowSpec[] { FormSpecs.LINE_GAP_ROWSPEC, RowSpec.decode("default:grow"), FormSpecs.LINE_GAP_ROWSPEC, }));
  4. JPanel panelMovieScrapers = new JPanel();
  5. panelMovieScrapers.setLayout(new FormLayout(
  6. new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
  7. FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("80dlu:grow"), FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
  8. panelMovieScrapers.add(lblMovieScraper, "2, 2, 11, 1");
  9. JScrollPane scrollPaneScraper = new JScrollPane();
  10. panelMovieScrapers.add(scrollPaneScraper, "2, 4, 5, 1, fill, fill");
  11. scrollPaneScraper.setViewportView(tableScraper);
  12. JPanel panelScraperDetails = new JPanel();
  13. new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("default:grow"), FormSpecs.RELATED_GAP_ROWSPEC, }));
  14. tpScraperDescription = new JTextPane();
  15. tpScraperDescription.setOpaque(false);
  16. tpScraperDescription.setEditorKit(new HTMLEditorKit());
  17. panelScraperDetails.add(tpScraperDescription, "2, 2, default, top");

代码示例来源:origin: org.swinglabs.swingx/swingx-all

  1. iconLabel = new JLabel(pane.getIcon());
  2. errorMessage = new JEditorPane();
  3. errorMessage.setEditable(false);
  4. errorMessage.setContentType("text/html");
  5. errorMessage.setEditorKitForContentType("text/plain", new StyledEditorKit());
  6. errorMessage.setEditorKitForContentType("text/html", new HTMLEditorKit());
  7. errorMessage.setOpaque(false);
  8. copyToClipboardButton.addActionListener(copyToClipboardListener);
  9. detailsPanel.setLayout(createDetailPanelLayout());
  10. detailsPanel.add(detailsScrollPane);
  11. detailsPanel.add(copyToClipboardButton);
  12. errorScrollPane = new JScrollPane(errorMessage);
  13. errorScrollPane.setBorder(new EmptyBorder(0,0,5,0));
  14. errorScrollPane.setOpaque(false);

代码示例来源:origin: stackoverflow.com

  1. public JComponent makeEditorPane(String bullet) {
  2. JEditorPane pane = new JEditorPane();
  3. pane.setContentType("text/html");
  4. pane.setEditable(false);
  5. if(bullet!=null) {
  6. HTMLEditorKit htmlEditorKit = (HTMLEditorKit)pane.getEditorKit();
  7. StyleSheet styleSheet = htmlEditorKit.getStyleSheet();
  8. styleSheet.addRule(String.format("ul{list-style-image:url(%s);margin:0px 20px;", u));
  9. JPanel p = new JPanel(new GridLayout(2,1));
  10. p.add(new JScrollPane(makeEditorPane(null)));
  11. p.add(new JScrollPane(makeEditorPane("bullet.png")));
  12. return p;
  13. JFrame f = new JFrame();
  14. f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  15. f.getContentPane().add(new HTMLTest2().makeUI());
  16. f.setSize(320, 320);
  17. f.setLocationRelativeTo(null);

代码示例来源:origin: stackoverflow.com

  1. public void run() {
  2. JFrame frame = new HTMLLabelTest();
  3. frame.pack();
  4. frame.setVisible(true);
  5. HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
  6. StyleSheet styleSheet = new StyleSheet();
  7. URL resource = getClass().getResource("/stylesheet.css");
  8. styleSheet.importStyleSheet(resource);
  9. htmlEditorKit.setStyleSheet(styleSheet);
  10. label.setPreferredSize(new Dimension(30,20));
  11. JPanel panel = new JPanel();
  12. panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
  13. panel.add(label);
  14. panel.setOpaque(true);

代码示例来源:origin: pentaho/pentaho-reporting

  1. /**
  2. * Creates a new, uninitialized module editor.
  3. */
  4. public DefaultModuleEditor() {
  5. messages = Messages.getInstance();
  6. contentpane = new JPanel();
  7. contentpane.setLayout( new VerticalLayout() );
  8. helpPane = new JEditorPane();
  9. helpPane.setEditable( false );
  10. helpPane.setEditorKit( new HTMLEditorKit() );
  11. helpPane.setPreferredSize( new Dimension( 600, 100 ) );
  12. final JPanel toolbar = new JPanel();
  13. toolbar.setLayout( new BorderLayout() );
  14. toolbar.add( new JScrollPane( helpPane ) );
  15. toolbar.setMinimumSize( new Dimension( 100, 150 ) );
  16. rootpane = new JSplitPane( JSplitPane.VERTICAL_SPLIT );
  17. try {
  18. // An ugly way of calling
  19. // rootpane.setResizeWeight(1);
  20. final Method m = rootpane.getClass().getMethod
  21. ( "setResizeWeight", new Class[] { Double.TYPE } ); //$NON-NLS-1$
  22. m.invoke( rootpane, new Object[] { new Double( 1 ) } );
  23. } catch ( Exception e ) {
  24. // ignored ...
  25. }
  26. rootpane.setBottomComponent( toolbar );
  27. rootpane.setTopComponent( new JScrollPane( contentpane ) );
  28. }

代码示例来源:origin: es.gob.afirma/afirma-core-firmaweb

  1. BrowserDialog(final String html, final Frame parent) {
  2. super(parent, WebSignMessages.getString("BrowserDialog.13"), true); //$NON-NLS-1$
  3. this.getAccessibleContext().setAccessibleParent(parent);
  4. final JEditorPane ep = new JEditorPane();
  5. ep.setEditable(false);
  6. ep.setEnabled(false);
  7. ep.addHyperlinkListener(this.linkListener);
  8. getContentPane().add(new JScrollPane(ep), BorderLayout.CENTER);
  9. setSize(600, 600);
  10. final JPanel sur = new JPanel();
  11. sur.add(new JButton(this.afirmar), BorderLayout.WEST);
  12. sur.add(new JButton(this.anoFirmar), BorderLayout.EAST);
  13. getContentPane().add(sur, BorderLayout.SOUTH);
  14. ep.setEditorKit(this.kit);
  15. try {
  16. final Document doc = ep.getDocument();
  17. this.kit.read(new StringReader(html), doc, 0);
  18. disableContent(ep);
  19. }
  20. catch (final Exception e) {
  21. LOGGER.severe(WebSignMessages.getString("BrowserDialog.14") + e); //$NON-NLS-1$
  22. }
  23. }

代码示例来源:origin: org.scijava/scijava-ui-swing

  1. textPane = new JTextPane();
  2. kit = new HTMLEditorKit();
  3. doc = new HTMLDocument();
  4. textPane.setEditorKit(kit);
  5. textPane.setDocument(doc);
  6. textPane.setEditable(false);
  7. splitPane.add(new JScrollPane(tree));
  8. splitPane.add(new JScrollPane(textPane));
  9. clearHistory.addActionListener(this);
  10. final JPanel buttonBar = new JPanel();
  11. buttonBar.setLayout(new BoxLayout(buttonBar, BoxLayout.X_AXIS));
  12. buttonBar.add(Box.createHorizontalGlue());
  13. buttonBar.add(clearHistory);

代码示例来源:origin: stackoverflow.com

  1. @Override
  2. public void run() {
  3. JFrame frame = new JFrame();
  4. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  5. final JEditorPane editorPane = new JEditorPane();
  6. editorPane.setEditorKit(new HTMLEditorKit());
  7. try {
  8. editorPane.setPage(new URL("http://weblogs.java.net/blog/alex2d/archive/2008/12/jwebpane_projec.html"));
  9. } catch (IOException ex) {
  10. final JPanel panel = new JPanel(new BorderLayout());
  11. panel.add(new JScrollPane(editorPane), BorderLayout.CENTER);
  12. panel.add(new JButton(new AbstractAction("SAVE") {
  13. @Override
  14. public void actionPerformed(ActionEvent e) {
  15. frame.setContentPane(panel);
  16. frame.setSize(600, 400);
  17. frame.setVisible(true);

代码示例来源:origin: stackoverflow.com

  1. JEditorPane jEditorPaneIsFollower = new JEditorPane();
  2. jEditorPaneIsFollower.setEditable(false);
  3. jEditorPaneIsFollower.setContentType("text/html");
  4. jEditorPaneIsFollower.setDocument(new HTMLDocument());
  5. jEditorPaneIsFollower.setEditorKit(new HTMLEditorKit());
  6. jEditorPaneIsFollower.setText(HTML_TEXT);
  7. ToolTipManager.sharedInstance().registerComponent(jEditorPaneIsFollower);
  8. return new JScrollPane(jEditorPaneIsFollower);
  9. JFrame f = new JFrame();
  10. f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  11. f.getContentPane().add(new HyperlinkTooltipTest().makeUI());
  12. f.setSize(320, 240);
  13. f.setLocationRelativeTo(null);

代码示例来源:origin: org.cytoscape/work-swing-impl

  1. dialog.setPreferredSize(new Dimension(500, 400));
  2. pane = new JEditorPane();
  3. pane.setEditable(false);
  4. pane.setContentType("text/html");
  5. final HTMLEditorKit htmlEditorKit = (HTMLEditorKit) pane.getEditorKit();
  6. final StyleSheet styleSheet = htmlEditorKit.getStyleSheet();
  7. styleSheet.addRule("ul {list-style-type: none;}");
  8. final JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
  9. buttonsPanel.add(cleanButton);
  10. final JScrollPane scrollPane = new JScrollPane(pane);

代码示例来源:origin: stackoverflow.com

  1. StyleSheet styleSheet = new StyleSheet();
  2. styleSheet.addRule("body {font-family:\"Arial\"; font-size:12; } ");
  3. HTMLEditorKit messageEditorPaneHTMLEditorKit = new HTMLEditorKit();
  4. messageEditorPaneHTMLEditorKit.setStyleSheet(styleSheet);
  5. HTMLDocument document = (HTMLDocument) messageEditorPaneHTMLEditorKit.createDefaultDocument();
  6. JEditorPane editorPane = new JEditorPane("text/html", "");
  7. editorPane.setEditorKit(messageEditorPaneHTMLEditorKit);
  8. editorPane.setDocument(document);
  9. });
  10. JFrame frame = new JFrame("Styling example");
  11. JPanel contentPane = new JPanel();
  12. contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
  13. contentPane.add(editorPane);
  14. contentPane.add(changeStyleButton);
  15. frame.setContentPane(contentPane);
  16. frame.setSize(300,300);
  17. frame.setLocationRelativeTo(null);

代码示例来源:origin: fr.ifremer/isis-fish

  1. $objectMap.put("$JScrollPane0", $JScrollPane0 = new JScrollPane());
  2. $JScrollPane0.setName("$JScrollPane0");
  3. SwingUtil.setComponentHeight($JScrollPane0,200);
  4. createDoc();
  5. createComboResult();
  6. $objectMap.put("$JPanel0", $JPanel0 = new JPanel());
  7. $JPanel0.setName("$JPanel0");
  8. $JPanel0.setLayout(new GridLayout(0, 3, 2, 2));
  9. createOk();
  10. createReset();
  11. setModalityType(Dialog.ModalityType.APPLICATION_MODAL);doc.setEditable(false);doc.setEditorKit(new HTMLEditorKit());doc.addHyperlinkListener(createHyperLinkListener());// registers 2 data bindings
  12. $registerDefaultBindings();
  13. $completeSetup();

代码示例来源:origin: stackoverflow.com

  1. JFrame jFrame = new JFrame();
  2. jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  3. Container container = jFrame.getContentPane();
  4. container.setLayout(new BorderLayout());
  5. container.add(new JTextField(), BorderLayout.NORTH);
  6. JEditorPane editorPane = new JEditorPane();
  7. editorPane.setEditorKit(new HTMLEditorKit());
  8. editorPane.setText("<html><body>Hello World</body></html>");
  9. container.add(editorPane, BorderLayout.CENTER);

代码示例来源:origin: stackoverflow.com

  1. "</html>";
  2. JEditorPane swingbox = new JEditorPane ();
  3. swingbox.setEditorKit(new HTMLEditorKit());
  4. swingbox.setContentType("text/html");
  5. swingbox.setText(html);
  6. JFrame frame=new JFrame("Example");
  7. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  8. frame.getContentPane().add(swingbox);
  9. Dictionary cache=(Dictionary)swingbox.getDocument().getProperty("imageCache");

代码示例来源:origin: stackoverflow.com

  1. + "<v><q><vn>5 </vn>De Rahab, Salma eut pour descendant Booz.<br/>De Ruth, Booz eut pour descendant Obed.</q></v></c></p>";
  2. final JFrame mainFrame = new JFrame("test");
  3. mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  4. final JTextPane field = new JTextPane();
  5. field.setContentType("text/html");
  6. HTMLEditorKit kit = (HTMLEditorKit) field.getEditorKit();
  7. HTMLDocument doc = (HTMLDocument) field.getDocument();
  8. kit.read(r, field.getDocument(), 0);
  9. } catch (IOException | BadLocationException ex) {
  10. Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
  11. kit.write(w, field.getDocument(), field.getSelectionStart(), field.getSelectionEnd()-field.getSelectionStart());
  12. System.out.println(w.toString());
  13. } catch (IOException | BadLocationException ex) {
  14. mainFrame.getContentPane().setLayout(new BorderLayout());
  15. mainFrame.getContentPane().add(field,BorderLayout.CENTER);
  16. mainFrame.setSize(500,500);
  17. mainFrame.setVisible(true);

代码示例来源:origin: stackoverflow.com

  1. JFrame frame = new JFrame();
  2. JEditorPane edPane = new JEditorPane();
  3. edPane.setContentType("text/html");
  4. System.out.println(edPane.getText());
  5. HTMLEditorKit hek = new HTMLEditorKit();
  6. edPane.setEditorKit(hek);
  7. doc.insertAfterEnd(body,"<img src="+ClassLoader.getSystemResource("thumbnail.png").toString()+">");
  8. System.out.println(edPane.getText());
  9. } catch(BadLocationException e) {
  10. frame.add(edPane);
  11. frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  12. frame.pack();
  13. frame.setVisible(true);

相关文章