`
zengxx1989
  • 浏览: 295490 次
  • 性别: Icon_minigender_1
  • 来自: 湖南
社区版块
存档分类
最新评论

在 JLabel 中打开链接

阅读更多
final JLabel lblUrl = new JLabel();
		lblUrl.setBounds(484, 38, 80, 18);

		uri = "www.hao123.com";
		lblUrl.setText("<html><a href='" + uri + "'>查看</a>");

		lblUrl.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

		lblUrl.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				Desktop desktop = Desktop.getDesktop();
				try {
					desktop.browse(new URI(uri));
				} catch (IOException e1) {
					e1.printStackTrace();
				} catch (URISyntaxException e1) {
					e1.printStackTrace();
				}
			}

		});
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics