ここでは、いくつかのカスタムJPanelを使用して、静的入力値で拡張および縮小します。
Javaタイマーは、パネルの表示時間を遅らせてスピードアップするために使用しています。
public class SlidingPanel extends JPanel {
private int paneHeight;
private int paneWidth;
private int comHeight;
private int comWidth;
private Timer everyspeedmillisec;
/**custom class for slide up and down actions for JPanel
*
*/
public SlidingPanel(LayoutManager layout,Dimension panedim) {
super(layout);
setPreferredSize(panedim);
paneHeight = (int)panedim.getHeight();;
paneWidth = (int) panedim.getWidth();
}
/**function for expanding Jpanel
*
*/
public void expand_sft_det(int speed ,JPanel slidingcom)
{
//Add Jpanel for sliding
this.add(slidingcom);
//パネルの高さと幅を取得します。これは、スライドの高さとして表示するものです。
comHeight=(int)slidingcom.getMinimumSize().getHeight();
comWidth=(int) slidingcom.getMinimumSize().getWidth();
//いくつかの静的な値でタイマーを初期化-中速)
everyspeedmillisec = new Timer(30, new ActionListener() {
private int count_timer=0;
public void actionPerformed(ActionEvent e) {
count_timer++;
if( paneHeight < comHeight){
setPreferredSize(new Dimension(paneWidth, paneHeight));
paneHeight+=20;
repaint();
revalidate();
}
else
everyspeedmillisec.stop() ;
}
});
everyspeedmillisec.start();
}
/**Jpanelを縮小するための関数**/
public void shrink_sft_det(int speed ,JPanel slidingcom) {
comHeight = (int)slidingcom.getMinimumSize().getHeight();
comWidth = (int)slidingcom.getMinimumSize().getWidth();
//一番上の位置までスライドするための高さ
paneHeight=0;
everyspeedmillisec = new Timer(30, new ActionListener() {
private int count_timer=0;
public void actionPerformed(ActionEvent e) {
count_timer++;
if( paneHeight < comHeight){
setPreferredSize(new Dimension(comWidth,comHeight));
comHeight-=20;
repaint();
revalidate();
}
else
everyspeedmillisec.stop() ;
}
});
everyspeedmillisec.start();
}
//クラスを宣言し、縮小するonclickイベントを使用します
public class SoftPanel extends JPanel implements ActionListener
, MouseListener {
JPanel MoredetPane;
JPanel SlidedetPane;
private JLabel SoftDOCLabel;
private JLabel SoftLocation;
private JLabel SoftUpdates;
private boolean mr_det_flag =true;
MoredetPane = new SlidingPanel(new GridLayout(1,1,5,5),new Dimension(300,1));
MoredetPane.setOpaque(false);
//Add some components
SlidedetPane = new JPanel(new GridLayout(3,2,50,25));
SlidedetPane.setPreferredSize(new Dimension(300,200));
SlidedetPane.setOpaque(false);
SoftDOCLabel = new JLabel("Software Date") ;
SoftLocation = new JLabel("Software Location") ;
SoftUpdates = new JLabel("Software Updates") ;
SlidedetPane.add(SoftDOCLabel);
SlidedetPane.add(new JLabel(softbean.getSoftDOC()));
SlidedetPane.add(SoftLocation);
SlidedetPane.add(new JLabel(softbean.getSoftPath()));
SlidedetPane.add( SoftUpdates);
SlidedetPane.add(new JLabel(""));
//Onclick events
modedetails_Label.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent clickeve) {
if(mr_det_flag){
mr_det_flag=false;
((SlidingPanel)MoredetPane).expand_sft_det(200,SlidedetPane);
add(SlidingPanel);
}
else{
mr_det_flag=true;
((SlidingPanel) MoredetPane).shrink_sft_det(0,SlidedetPane);
}
});
add( MoredetPane );
}