タイトル
TOPJavaSwingJDesktopPane,JInternalFrame → This Page

JDesktopPane,JInternalFrame@Swing サンプル01

概要

Java - Swing - JDesktopPane,JInternalFrame のサンプルです。
・色々なコンストラクタ

サンプルイメージ

サンプル画像


サンプルソース

import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;

/**
 * JDesktopPane サンプル01
 * ・色々なコンストラクタ
 * 
 * @author みっちー
 */
public class JDesktopPane01 extends JFrame {
	
	private static final long serialVersionUID = 1L;
	
	/**
	 * 開始メソッド
	 * 
	 * @param args	パラメータ
	 */
	public static void main(String[] args) {
		JDesktopPane01 frame = new JDesktopPane01();
		
		// 閉じるボタンをクリックされた場合の動作を設定
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		// ウインドウのタイトルを設定
		frame.setTitle("JDesktopPane サンプル01");
		
		// フレームの X座標、Y座標、幅、高さを設定
		frame.setBounds(100, 200, 450, 390);
		
		// フレームを表示(これをしないと透明のフレームが立ち上がってしまう)
		frame.setVisible(true);
	}
	
	/**
	 * コンストラクタ
	 */
	public JDesktopPane01() {
		// デスクトップパネを生成
		JDesktopPane desktop = new JDesktopPane();
		
		// 内部フレームを生成
		JInternalFrame iframe1 = new JInternalFrame();
		JInternalFrame iframe2 = new JInternalFrame("title2");
		JInternalFrame iframe3 = new JInternalFrame("title3", true);
		JInternalFrame iframe4 = new JInternalFrame("title4", true, true);
		JInternalFrame iframe5 = new JInternalFrame("title5", true, true, true);
		JInternalFrame iframe6 = new JInternalFrame("title6", true, true, true, true);
		
		// 内部フレームのサイズと位置をセット
		iframe1.setBounds(10, 10, 200, 100);
		iframe2.setBounds(220, 10, 200, 100);
		iframe3.setBounds(10, 120, 200, 100);
		iframe4.setBounds(220, 120, 200, 100);
		iframe5.setBounds(10, 230, 200, 100);
		iframe6.setBounds(220, 230, 200, 100);
		
		// 内部フレームを表示
		iframe1.setVisible(true);
		iframe2.setVisible(true);
		iframe3.setVisible(true);
		iframe4.setVisible(true);
		iframe5.setVisible(true);
		iframe6.setVisible(true);
		
		// デスクトップパネに内部フレームを追加
		desktop.add(iframe1);
		desktop.add(iframe2);
		desktop.add(iframe3);
		desktop.add(iframe4);
		desktop.add(iframe5);
		desktop.add(iframe6);
		
		// パネを追加
		getContentPane().add(desktop);
	}
}

サンプルソースのダウンロード

ソースのダウンロード(Eclipse用のプロジェクトファイルも同梱)

更新履歴

2016/08/27 新規作成


TOPJavaSwingJDesktopPane,JInternalFrame → This Page