Swing/Desktop のバックアップ差分(No.10)
- バックアップ一覧
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/Desktop へ行く。
- 1 (2007-02-19 (月) 16:02:04)
- 2 (2007-02-20 (火) 16:39:54)
- 3 (2007-07-26 (木) 17:09:54)
- 4 (2008-02-19 (火) 15:15:17)
- 5 (2012-01-27 (金) 17:18:20)
- 6 (2013-09-15 (日) 00:18:32)
- 7 (2014-12-30 (火) 15:32:42)
- 8 (2016-04-15 (金) 12:43:38)
- 9 (2017-08-02 (水) 15:31:35)
- 10 (2018-08-03 (金) 14:08:29)
- 11 (2018-11-01 (木) 21:40:51)
- 12 (2020-11-02 (月) 11:25:42)
- 13 (2022-09-27 (火) 17:11:30)
- 追加された行はこの色です。
- 削除された行はこの色です。
---
category: swing
folder: Desktop
title: Desktopでブラウザを起動
tags: [Desktop, Html]
author: aterai
pubdate: 2007-02-19T16:02:04+09:00
description: JDK 6で導入されたDesktopを使ってブラウザを起動します。
image: https://lh5.googleusercontent.com/_9Z4BYR88imo/TQTKu9HhvrI/AAAAAAAAAWc/iMheiQnF4hQ/s800/Desktop.png
---
* 概要 [#summary]
`JDK 6`で導入された`Desktop`を使ってブラウザを起動します。
#download(https://lh5.googleusercontent.com/_9Z4BYR88imo/TQTKu9HhvrI/AAAAAAAAAWc/iMheiQnF4hQ/s800/Desktop.png)
* サンプルコード [#sourcecode]
#code(link){{
if (!Desktop.isDesktopSupported()) {
return;
}
try {
Desktop.getDesktop().browse(new URI(href));
} catch (IOException | URISyntaxException ex) {
ex.printStackTrace();
}
}}
* 解説 [#explanation]
`Desktop`を使用することで、ブラウザのほかにも、メーラーや拡張子に関連付けられたデフォルトのアプリケーションを起動することが出来るようになります。
このため、`OS`毎に`Runtime.getRuntime().exec(String[])`でアプリケーションを切り替えなくても、ブラウザを起動することができます。
* 参考リンク [#reference]
- [https://docs.oracle.com/javase/jp/8/docs/api/java/awt/Desktop.html Desktop (Java Platform SE 8)]
//- [http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/desktop_api/ Using the Desktop API in Java SE 6]
- [http://www.oracle.com/technetwork/articles/javase/index-135182.html Using the Desktop API in Java SE 6]
- [[Browserを起動>Swing/BrowserLauncher]]
* コメント [#comment]
#comment
#comment