スプリットペインの中にスプリットペインを配置する
広告
スプリットペイン自身もコンポーネントですのでスプリットペインの左右の領域に他のスプリットペインを配置することも可能です。スプリットペインをネストして利用することでより複雑なレイアウトが可能となります。
次のサンプルでは画面を3分割して利用するようにスプリットペインをネストして配置してあります。
import javax.swing.*;
import java.awt.BorderLayout;
public class JSplitPaneTest13 extends JFrame{
public static void main(String[] args){
JSplitPaneTest13 frame = new JSplitPaneTest13();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(10, 10, 300, 200);
frame.setTitle("タイトル");
frame.setVisible(true);
}
JSplitPaneTest13(){
JSplitPane splitpane = new JSplitPane();
JPanel leftPanel = new JPanel();
JButton leftButton = new JButton("Left");
leftPanel.add(leftButton);
JSplitPane rightSplitpane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
JPanel topPanel = new JPanel();
JButton topButton = new JButton("Top");
topPanel.add(topButton);
JPanel bottomPanel = new JPanel();
JButton bottomButton = new JButton("Bottom");
bottomPanel.add(bottomButton);
rightSplitpane.setLeftComponent(topPanel);
rightSplitpane.setRightComponent(bottomPanel);
splitpane.setLeftComponent(leftPanel);
splitpane.setRightComponent(rightSplitpane);
getContentPane().add(splitpane, BorderLayout.CENTER);
}
}
上記をコンパイルした後で実行すると次のように表示されます。
( Written by Tatsuo Ikura )
著者 / TATSUO IKURA
これから IT 関連の知識を学ばれる方を対象に、色々な言語でのプログラミング方法や関連する技術、開発環境構築などに関する解説サイトを運営しています。