タイトル
TOPJavaSwingJSplitPane → This Page

JSplitPane@Swing サンプル09

概要

Java - Swing - JSplitPane のサンプルです。
・分割パネを入れ子で設定

解説

分割パネの中に、さらに別の分割パネを設置しています。

サンプルイメージ

サンプル画像


サンプルソース

import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSplitPane;

/**
 * JSplitPane サンプル09
 * ・分割パネを入れ子で設定
 * 
 * @author みっちー
 */
public class JSplitPane09 extends JFrame {
	
	private static final long serialVersionUID = 1L;
	
	/**
	 * 開始メソッド
	 * 
	 * @param args	パラメータ
	 */
	public static void main(String[] args) {
		JSplitPane09 frame = new JSplitPane09();
		
		// 閉じるボタンをクリックされた場合の動作を設定
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		// ウインドウのタイトルを設定
		frame.setTitle("JSplitPane サンプル09");
		
		// フレームの X座標、Y座標、幅、高さを設定
		frame.setBounds(100, 200, 400, 300);
		
		// フレームを表示(これをしないと透明のフレームが立ち上がってしまう)
		frame.setVisible(true);
	}
	
	/**
	 * コンストラクタ
	 */
	public JSplitPane09() {
		// パネルを作成
		JPanel panelBase = new JPanel();
		panelBase.setLayout(new GridLayout(1, 1, 5, 5));
		
		// ボタンを生成
		JButton button1 = new JButton("Left");
		JButton button2 = new JButton("Right-Top");
		JButton button3 = new JButton("Right-Bottom");
		
		// 分割パネを生成
		JSplitPane splitPane1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
		JSplitPane splitPane2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
		
		// コンポーネントを追加
		splitPane2.setTopComponent(button2);
		splitPane2.setBottomComponent(button3);
		splitPane1.setLeftComponent(button1);
		splitPane1.setRightComponent(splitPane2);
		
		// 分割パネを追加
		panelBase.add(splitPane1);
		panelBase.add(splitPane2);
		
		// パネを追加
		getContentPane().add(panelBase);
	}
}

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

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

更新履歴

2016/08/25 新規作成


TOPJavaSwingJSplitPane → This Page