タイトル
TOPJavaSwingJDesktopPane,JInternalFrame → This Page

JDesktopPane,JInternalFrame@Swing サンプル07

概要

Java - Swing - JDesktopPane,JInternalFrame のサンプルです。
・内部フレームにレイヤーを設定

解説

内部フレームはそれぞれレイヤー値を保持しています。
初期値は 0 です。
レイヤー値が大きい内部フレームほど手前に表示されます。
サンプルでは内部フレーム3のレイヤー値を0から1に変更しています。

サンプルイメージ

サンプル画像


サンプルソース

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

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

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

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

更新履歴

2016/08/27 新規作成


TOPJavaSwingJDesktopPane,JInternalFrame → This Page