解答例 - 実習課題3 - 6.コンテナ
(実習課題3)
上のサンプルウィンドウのように左右にイメージを表示するウィンドウを作成しなさい。またその際、以下の点を試してみる事。
- 「JSplitPane」で引数を2つとるコンストラクタを使用する。2つ目の引数を「true」にした場合と「false」にした場合で動作がどのように変わるか確かめなさい。
- 「setDividerSize」メソッドで、分割線の太さを変えなさい。
解答例
/**
* SpritPaneFrame.java
* TECHSCORE Javaユーザインタフェース6章 実習課題3
*
* Copyright (c) 2004 Four-Dimensional Data, Inc.
*/
package com.techscore.ui.chapter6.exercise3;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSplitPane;
public class SplitPaneFrame extends JFrame {
public SplitPaneFrame() {
super("SplitPaneFrame");
setDefaultCloseOperation(EXIT_ON_CLOSE);
// 2つ目の引数で再描画のタイミングを制御
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false);
getContentPane().add(splitPane);
splitPane.setLeftComponent(new JLabel(new ImageIcon("com/techscore/ui/chapter6/exercise3/globe.jpg")));
splitPane.setRightComponent(new JLabel(new ImageIcon("com/techscore/ui/chapter6/exercise3/cone.jpg")));
splitPane.setDividerSize(20);
pack();
}
public static void main(String args[]) {
new SplitPaneFrame().setVisible(true);
}
}

