必要なときにさまざまなパネルをさまざまな時間に設定する、単純な拡張JSplitPaneがあります。具体的には、上下に分けて、下の部分を頻繁に入れ替えています。毎回、スライダーの位置を希望どおりにリセットしますが、ときどきジャンプして画面の上部に再配置されます(常にではありません)。
これが私のコードです:
public class MainPanel extends JSplitPane{
public Screen screen;
public int height;
public ControlPanel curPanel;
public MainPanel(Screen screen, int height){
super(JSplitPane.VERTICAL_SPLIT);
this.screen = screen;
this.height = height;
setDividerSize(2);
setEnabled(false);
setTopComponent(screen);
setToInitControls();
}
public void setToInitControls(){
InitControls initCtrls = new InitControls(this);
setBottomComponent(initCtrls);
curPanel = initCtrls;
setDividerLocation(height / 4 * 3);
}
public void setToConfigControls(){
ConfigControls configCtrls = new ConfigControls(this);
setBottomComponent(configCtrls);
curPanel = configCtrls;
setDividerLocation(height / 4 * 3);
}
public void setToWaitControls(){
WaitControls waitCtrls = new WaitControls(this);
setBottomComponent(null);
setBottomComponent(waitCtrls);
curPanel = waitCtrls;
setDividerLocation(height / 4 * 3);
}
//and so on (I have more methods like these further down)
//OVERRIDES: I figured overriding these might help. It didn't.
@Override
public int getMinimumDividerLocation(){
return (height / 4 * 3);
}
@Override
public int getMaximumDividerLocation(){
return (height / 4 * 3);
}
}
基本的に、私は「setTo ... Controls()」メソッドを使用して下部パネルを交換します。パネルの好みのサイズに関係なく、スライダーを配置した場所に置いたままにする方法はありますか?そうでない場合は、パネルにどのような形をしてフィットするかを知らせるにはどうすればよいですか?すべての提案をありがとう!
編集:これらのパネルはレイアウトを使用していないことに注意してください。これらは、マウス/キーボードリスナーを使用し、独自のグラフィックを使用してペイントするカスタムパネルです。