JEditorPaneのハイパーリンクから外部ブラウザを起動する
JEditorPaneはHTML形式を表示させるのに便利です。
ここでは、ハイパーリンク表示とハイパーリンクをクリックした時にOS既存ブラウザを起動するコードをメモします。
↑リンクをクリックするとブラウザが起動しリンクを表示します。
ソースコードはこちら。
require 'rubeus' Rubeus::Swing.irb JFrame.new do |f| JScrollPane.new do @editor = JEditorPane.new @editor.editable = false @editor.content_type = "text/html" @editor.listen :hyperlink do |e| if e.event_type == javax.swing.event.HyperlinkEvent::EventType::ACTIVATED java.awt.Desktop.desktop.browse(e.url.to_uri) end end @editor.text = "<a href='http://d.hatena.ne.jp/shingo-zukunashi/'>sample link</a>" end f.location_relative_to = nil f.pack f.visible = true end
JEditorPaneて便利ですネ。
とりあえず、ここまで。