当前位置: 首页>>代码示例>>Java>>正文


Java JEditorPane.addHyperlinkListener方法代码示例

本文整理汇总了Java中javax.swing.JEditorPane.addHyperlinkListener方法的典型用法代码示例。如果您正苦于以下问题:Java JEditorPane.addHyperlinkListener方法的具体用法?Java JEditorPane.addHyperlinkListener怎么用?Java JEditorPane.addHyperlinkListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JEditorPane的用法示例。


在下文中一共展示了JEditorPane.addHyperlinkListener方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getErrorMessage

import javax.swing.JEditorPane; //导入方法依赖的package包/类
private JEditorPane getErrorMessage() {
    JEditorPane errorMsg = new JEditorPane();

    errorMsg.setEditable(false);
    errorMsg.setPreferredSize(new Dimension(700, 130));
    errorMsg.setBackground(null);
    // Text font
    Font font = new Font("Sans", Font.PLAIN, 6);
    errorMsg.setFont(font);
    // Handle HTML
    errorMsg.setEditorKit(new HTMLEditorKit());
    errorMsg.addHyperlinkListener(this);

    errorMsg.setText(ERROR_MSG);

    return errorMsg;
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:18,代码来源:BugReportDialog.java

示例2: HelpWindow

import javax.swing.JEditorPane; //导入方法依赖的package包/类
public HelpWindow(String title, URL contents) {
  super(title);
  setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
  setJMenuBar(MenuManager.getInstance().getMenuBarFor(this));

  pane = new JEditorPane();
  pane.setEditable(false);
  pane.addHyperlinkListener(this);

  /*
   * Allow <src> tag to display images from the module DataArchive
   * where no pathname included in the image name.
   */
  pane.setContentType("text/html"); //$NON-NLS-1$
  XTMLEditorKit myHTMLEditorKit = new HtmlChart.XTMLEditorKit();
  pane.setEditorKit(myHTMLEditorKit);

  JScrollPane scroll = new ScrollPane(pane);
  add(scroll);
  update(contents);
  pack();
  Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
  int width = Math.max(d.width / 2, getSize().width);
  int height = Math.max(d.height / 2, getSize().height);
  width = Math.min(width, d.width * 2 / 3);
  height = Math.min(height, d.height * 2 / 3);
  setSize(width, height);
  setLocation(d.width / 2 - width / 2, 0);
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:30,代码来源:HelpWindow.java

示例3: DialogHelpWindow

import javax.swing.JEditorPane; //导入方法依赖的package包/类
public DialogHelpWindow(String title, URL contents, Dialog parent) {
  super(parent);
  setTitle(title);
  setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
  //setJMenuBar(MenuManager.getInstance().getMenuBarFor(this));

  pane = new JEditorPane();
  pane.setEditable(false);
  pane.addHyperlinkListener(this);

  /*
   * Allow <src> tag to display images from the module DataArchive
   * where no pathname included in the image name.
   */
  pane.setContentType("text/html"); //$NON-NLS-1$
  XTMLEditorKit myHTMLEditorKit = new HtmlChart.XTMLEditorKit();
  pane.setEditorKit(myHTMLEditorKit);

  JScrollPane scroll = new ScrollPane(pane);
  add(scroll);
  update(contents);
  pack();
  Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
  int width = Math.max(d.width / 2, getSize().width);
  int height = Math.max(d.height / 2, getSize().height);
  width = Math.min(width, d.width * 2 / 3);
  height = Math.min(height, d.height * 2 / 3);
  setSize(width, height);
  setLocation(d.width / 2 - width / 2, 0);
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:31,代码来源:DialogHelpWindow.java

示例4: FlickrSettingsPanel

import javax.swing.JEditorPane; //导入方法依赖的package包/类
public FlickrSettingsPanel()
{
	apiKey = new JTextField();
	apiSharedSecret = new JTextField();

	// Yuck, this seems to be the minimal amount of code to get a clickable
	// and styled link
	// (copied from the Cron link in the scheduler)
	JEditorPane apiKeyHelp = new JEditorPane();
	apiKeyHelp.setEditorKit(new HTMLEditorKit());
	apiKeyHelp.setDocument(new HTMLDocument());
	apiKeyHelp.setEditable(false);
	apiKeyHelp.setText("<html><head><style>" + "<!--a{color:#0000cc;text-decoration: none;}//--></style></head>"
		+ "<body>" + getString("settings.label.apikeyhelp"));
	apiKeyHelp.addHyperlinkListener(new HyperlinkListener()
	{
		@Override
		public void hyperlinkUpdate(HyperlinkEvent e)
		{
			if( e.getEventType() == HyperlinkEvent.EventType.ACTIVATED )
			{
				getClientService().showDocument(e.getURL(), null);
			}
		}
	});
	apiKeyHelp.setBackground(new JPanel().getBackground());

	add(apiKeyHelp, "span 2");

	add(new JLabel(getString("settings.label.apikey")));
	add(apiKey);
	add(new JLabel(getString("settings.label.apisharedsecret")));
	add(apiSharedSecret);
}
 
开发者ID:equella,项目名称:Equella,代码行数:35,代码来源:FlickrSettingsPanel.java

示例5: buildDetail

import javax.swing.JEditorPane; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void buildDetail(String id, JPanel panel) {
    if (this.id.equals(id)) return;

    panel.setLayout(new MigLayout("wrap 1, center"));

    JLabel header = Utility.localizedHeaderLabel(Messages.nameKey(id),
        SwingConstants.LEADING, FontLibrary.FontSize.SMALL);
    panel.add(header, "align center, wrap 20");

    JEditorPane editorPane = new JEditorPane("text/html",
        Messages.getDescription(id)) {

        @Override
        public void paintComponent(Graphics g) {
            Graphics2D graphics2d = (Graphics2D) g;
            graphics2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                                        RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
            /*
            graphics2d.setRenderingHint(RenderingHints.KEY_RENDERING,
                                        RenderingHints.VALUE_RENDER_QUALITY);
            graphics2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
                                        RenderingHints.VALUE_FRACTIONALMETRICS_ON);
            */
            super.paintComponent(graphics2d);
        }
    };
    editorPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES,
                                 Boolean.TRUE);
    editorPane.setFont(panel.getFont());
    editorPane.setOpaque(false);
    editorPane.setEditable(false);
    editorPane.addHyperlinkListener(colopediaPanel);

    panel.add(editorPane, "width 95%");
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:40,代码来源:ConceptDetailPanel.java

示例6: makeEditorPane

import javax.swing.JEditorPane; //导入方法依赖的package包/类
/**
 * Create a JEditorPane that will convert the text into html with working hyperlinks.
 * This can be included in a messageDialog with, e.g.
 * JOptionPane.showMessageDialog(null, ep)
 * @param text
 * @return
 */
public static JEditorPane makeEditorPane(String text) {
    // for copying style
    JLabel label = new JLabel();
    Font font = label.getFont();

    // create some css from the label's font
    StringBuffer style = new StringBuffer("font-family:" + font.getFamily() + ";");
    style.append("font-weight:" + (font.isBold() ? "bold" : "normal") + ";");
    style.append("font-size:" + font.getSize() + "pt;");
	
    //need to use editor pane and hyperlink listener so that we can include hyperlinks in help text
    JEditorPane ep = new JEditorPane("text/html", "<html><body style=\"" + style + "\">" //
            + text //
            + "</body></html>");

    ep.addHyperlinkListener(new HyperlinkListener()
    {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent e)
        {
            if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED))
            	BrowseURL.browseURL(e.getURL().toString());
        }
    });
	ep.setEditable(false);
	ep.setBackground(label.getBackground());
	
	return ep;
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:37,代码来源:GeneralUtils.java

示例7: showHelp

import javax.swing.JEditorPane; //导入方法依赖的package包/类
/**
 * Brings up a window with a scrolling text pane that display the help
 * information.
 */
private void showHelp() {
    JDialog dialog = new JDialog(this, resources.getString("dialog.help.title"));
    final JEditorPane helpText = new JEditorPane();
    try {
        URL url = getClass().getResource("GridWorldHelp.html");

        helpText.setPage(url);
    } catch (Exception eh) {
        helpText.setText(resources.getString("dialog.help.error"));
    }
    helpText.setEditable(false);
    helpText.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent ev) {
            if (ev.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
                try {
                    helpText.setPage(ev.getURL());
                } catch (Exception ex) {
                }
        }
    });
    JScrollPane sp = new JScrollPane(helpText);
    sp.setPreferredSize(new Dimension(650, 500));
    dialog.getContentPane().add(sp);
    dialog.setLocation(getX() + getWidth() - 200, getY() + 50);
    dialog.pack();
    dialog.setVisible(true);
}
 
开发者ID:CBSkarmory,项目名称:AWGW,代码行数:32,代码来源:WorldFrame.java

示例8: aboutMenuItemActionPerformed

import javax.swing.JEditorPane; //导入方法依赖的package包/类
private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuItemActionPerformed
Font font = new JLabel().getFont();

// Load HTML and set style to match the application's style
String html
	= Translations.get(
		"RaceFrame.help.about",
		font.getFamily(),
		(font.isBold() ? "bold" : "normal"),
		"" + font.getSize() + "pt");

// Create HTML content pane
JEditorPane ep = new JEditorPane("text/html", html);

// Handle link clicks
ep.addHyperlinkListener((HyperlinkEvent e) -> {
    if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
	try {
	    Desktop.getDesktop().browse(e.getURL().toURI());
	} catch (IOException | URISyntaxException ex) {
	    Logger.getLogger(RaceFrame.class.getName()).log(Level.SEVERE, null, ex);
	}
    }
});
ep.setEditable(false);
ep.setBackground(new JOptionPane().getBackground());

// Show dialog
JOptionPane.showMessageDialog(null, ep);
   }
 
开发者ID:Follpvosten,项目名称:schneckenrennen,代码行数:31,代码来源:RaceFrame.java

示例9: createMessagePane

import javax.swing.JEditorPane; //导入方法依赖的package包/类
private JEditorPane createMessagePane( String htmlMessage ) {
    JEditorPane messagePane = new JEditorPane("text/html", htmlMessage);
    messagePane.setEditable(false);
    messagePane.setOpaque(false);
    messagePane.addHyperlinkListener( (HyperlinkEvent hyperLink) -> {
        if (HyperlinkEvent.EventType.ACTIVATED.equals(hyperLink.getEventType())) {
            try {
                Desktop.getDesktop().browse( hyperLink.getURL().toURI() );
            } catch (URISyntaxException | IOException ex) {
                LOGGER.log( Level.WARNING, "Failed to open URL: " + hyperLink.getURL(), ex );
            }
        }
    });
    return messagePane;
}
 
开发者ID:chipKIT32,项目名称:chipKIT-importer,代码行数:16,代码来源:ShowChipKitImportWizardAction.java

示例10: showErrorMessage

import javax.swing.JEditorPane; //导入方法依赖的package包/类
private void showErrorMessage() {
		 // for copying style
	    JLabel label = new JLabel();
	    Font font = label.getFont();

	    // create some css from the label's font
	    StringBuffer style = new StringBuffer("font-family:" + font.getFamily() + ";");
	    style.append("font-weight:" + (font.isBold() ? "bold" : "normal") + ";");
	    style.append("font-size:" + font.getSize() + "pt;");
		 JEditorPane ep = new JEditorPane("text/html", "<html><body style=\"" + style + "\">"//
		            + "TextToSpeech executable not found."
		            + "<br>Please make sure that the path variable leads to the espeak executable!"
		            + "<br>If you do not have espeak installed yet, please download it from <a href=http://espeak.sourceforge.net\">http://espeak.sourceforge.net</a>."
		            + "<br>Linux users can use the following command: 'sudo apt-get install espeak' " //
		            + "</body></html>");

		    // handle link events
		    ep.addHyperlinkListener(new HyperlinkListener()
		    {
		        @Override
		        public void hyperlinkUpdate(HyperlinkEvent e)
		        {
		            if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED))
		            	if (Desktop.isDesktopSupported()) {
		            	      Desktop desktop = Desktop.getDesktop();
		            	      try {
		            	        desktop.browse(e.getURL().toURI());
		            	      } catch (IOException f) {
		            	        JOptionPane.showMessageDialog(null,
		            	            "Failed to launch the link, your computer is likely misconfigured.",
		            	            "Cannot Launch Link",JOptionPane.WARNING_MESSAGE);
		            	      } catch (URISyntaxException e1) {
								// TODO Auto-generated catch block
								e1.printStackTrace();
							}
		            	    } else {
		            	      JOptionPane.showMessageDialog(null,
		            	          "Java is not able to launch links on your computer.",
		            	          "Cannot Launch Link", JOptionPane.WARNING_MESSAGE);
		            	    }
//		                ProcessHandler.launchUrl(e.getURL().toString()); // roll your own link launcher or use Desktop if J6+
		        }
		    });
		    ep.setEditable(false);
		    ep.setBackground(label.getBackground());

//
//		JOptionPane.showMessageDialog(PlayRelease.startGui, "TextToSpeech executable not found.\nPlease make sure that the path variable leads to the espeak executable!\nIf you do not have espeak installed yet, please downlaod it from '<HTML>http://espeak.sourceforge.net/</HTML>'."
//				+ "\n Linux users can use the following command: sudo apt-get install espeak","Error occurred",JOptionPane.ERROR_MESSAGE);
		JOptionPane.showMessageDialog(PlayRelease.startGui, ep,"Error occurred",JOptionPane.ERROR_MESSAGE);
	}
 
开发者ID:CognitiveModeling,项目名称:BrainControl,代码行数:52,代码来源:TextToSpeech.java


注:本文中的javax.swing.JEditorPane.addHyperlinkListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。