Over a million developers have joined DZone.

JLabel Link: Open Browser Form Swing GUI By Clicking On Link

·
// Opens a browser on a specific site when clicking on the JLabel



                link = new JLabel(" Click here to find the PUID          \n");
		link.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		link.addMouseListener(new MouseAdapter() {
		   public void mouseClicked(MouseEvent e) {
		      if (e.getClickCount() > 0) {
		    	  if (Desktop.isDesktopSupported()) {
		                Desktop desktop = Desktop.getDesktop();
		                try {
		                		URI uri = new URI("http://www.nationalarchives.gov.uk/PRONOM/Format/proFormatSearch.aspx?status=new");
		                        desktop.browse(uri);
		                } catch (IOException ex) {
		                        // do nothing
		                } catch (URISyntaxException ex) {
							//do nothing
						}
		        } else {
		               //do nothing
		        }

		      }
		   }
		});
Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}