SmPanelSwitch

SmPanelSwitch 是可切换显示面板的控件。其接口说明可参见 SmPanelSwitch 接口说明文档。

示范代码

SmPanelSwitch 控件使用的示例代码如下:

private void initComponents() {
	this.smPanelSwitch = new SmPanelSwitch();
	this.button1 = new JButton("按钮1");
	this.button2 = new JButton("按钮2");
	this.button3 = new JButton("按钮3");
	JLabel label1 = new JLabel("面板1");
	this.panel1 = new JPanel(new BorderLayout());
	this.panel1.add(label1,BorderLayout.CENTER);
	JLabel label2 = new JLabel("面板2");
	this.panel2 = new JPanel(new BorderLayout());
	this.panel2.add(label2,BorderLayout.CENTER);
	JLabel label3 = new JLabel("面板3");
	this.panel3 = new JPanel(new BorderLayout());
	this.panel3.add(label3,BorderLayout.CENTER);
	//添加三个不同的面板
	this.smPanelSwitch.addPanel("面板1",this.panel1);
	this.smPanelSwitch.addPanel("面板2",this.panel2);
	this.smPanelSwitch.addPanel("面板3",this.panel3);
	this.smPanelSwitch.switchPanel("面板2");
}
private void initListener() {
	ActionListener actionListener = new ActionListener() {
		@Override
		//根据点击的按钮,切换不同的面板
		public void actionPerformed(ActionEvent e) {
			if (e.getSource().equals(button1)) {
			smPanelSwitch.switchPanel("面板1");
			}else if (e.getSource().equals(button2)) {
				smPanelSwitch.switchPanel("面板2");
			}else if (e.getSource().equals(button3)) {
				smPanelSwitch.switchPanel("面板3");
			}
			smPanelSwitch.revalidate();
			smPanelSwitch.repaint();
		}
	};
	this.button1.addActionListener(actionListener);
	this.button2.addActionListener(actionListener);
	this.button3.addActionListener(actionListener);
}

SmPanelSwitch 控件显示效果如下: