- Home ›
 - Swing ›
 - JSplitPaneクラス ›
 - HERE
 
仕切線(ディバイダ)のサイズを設定する
広告
仕切線の幅(又は高さ)を設定する方法を確認します。JSplitPaneクラスで用意されている「setDividerSize」メソッドを使います。
setDividerSize public void setDividerSize(int newSize)
ディバイダのサイズを設定します。 パラメータ: newSize - ディバイダのサイズをピクセル数で指定する int 値
引数に仕切線のサイズをint型の値で指定します。単位はピクセルです。
実際の使い方は次のようになります。
JSplitPane splitpane = new JSplitPane(); splitpane.setDividerSize(5);
サンプルプログラム
では簡単なサンプルを作成して試してみます。
import javax.swing.*;
import java.awt.BorderLayout;
public class JSplitPaneTest9 extends JFrame{
  public static void main(String[] args){
    JSplitPaneTest9 frame = new JSplitPaneTest9();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBounds(10, 10, 300, 200);
    frame.setTitle("タイトル");
    frame.setVisible(true);
  }
  JSplitPaneTest9(){
    JSplitPane splitpane = new JSplitPane();
    splitpane.setDividerSize(20);
    JPanel leftPanel = new JPanel();
    JButton leftButton = new JButton("Left");
    leftPanel.add(leftButton);
    JPanel rightPanel = new JPanel();
    JButton rightButton = new JButton("Right");
    rightPanel.add(rightButton);
    splitpane.setLeftComponent(leftPanel);
    splitpane.setRightComponent(rightPanel);
    getContentPane().add(splitpane, BorderLayout.CENTER);
  }
}
			上記をコンパイルした後で実行すると次のように表示されます。
			
			
( Written by Tatsuo Ikura )
				
JavaDrive