---
title: "Java实现类Windows导航栏"
author: "mmdev"
date: "2007-12-18T15:17:00Z"
tags: []
slug: "java-windows"
draft: false
lastmod: "2012-04-14T20:14:10Z"
id: 1486368
url: "https://mmdev.iteye.com/blog/1486368"
---

Java实现类Windows导航栏

在Windows系统中，通常都会有左侧导航栏以供选择，而Java架构下并没有给我们提供同样的组件，但是构建同样的东西实际上是很容易的。

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)packageorg.loon.framework.swing.test;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjava.awt.BorderLayout;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjava.awt.Color;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjava.awt.Component;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjava.awt.Dimension;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjava.awt.EventQueue;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjava.awt.Font;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjava.awt.GradientPaint;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjava.awt.Graphics;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjava.awt.Graphics2D;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjava.awt.GridLayout;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjava.awt.Insets;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjava.awt.Rectangle;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjava.awt.event.ComponentAdapter;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjava.awt.event.ComponentEvent;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjava.awt.event.MouseAdapter;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjava.awt.event.MouseEvent;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjava.util.ArrayList;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjava.util.Iterator;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjava.util.List;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjavax.swing.BorderFactory;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjavax.swing.ButtonGroup;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjavax.swing.JCheckBox;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjavax.swing.JComponent;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjavax.swing.JFrame;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjavax.swing.JLabel;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjavax.swing.JPanel;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjavax.swing.JRadioButton;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjavax.swing.JScrollPane;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjavax.swing.JSplitPane;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjavax.swing.SpringLayout;  
importjavax.swing.WindowConstants;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjavax.swing.border.Border;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)/\*\*\*//\**  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*&lt;p&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*Title:LoonFramework  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*&lt;/p&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*&lt;p&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*Description:  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*&lt;/p&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*&lt;p&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*Copyright:Copyright(c)2007  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*&lt;/p&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*&lt;p&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*Company:LoonFramework  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*&lt;/p&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)*  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*@authorchenpeng  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*@email：ceponline@yahoo.com.cn  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*@version0.1  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)publicclassExampleAccordionextendsJPanel...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)/\*\*\*//\**  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)*  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)privatestaticfinallongserialVersionUID=1L;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)privatefinalJPanelpanel=newJPanel();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)privatefinalJLabellabel=newJLabel();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)//分割窗体  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)privatefinalJSplitPanesplit=newJSplitPane();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)privatefinalJScrollPanescroll;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)//折叠效果  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)publicExampleAccordion()...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)super(newBorderLayout());  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)panel.setOpaque(true);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)panel.setBackground(newColor(116,149,226));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)//滚动条  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)scroll=newJScrollPane(JScrollPane.VERTICAL\_SCROLLBAR\_AS\_NEEDED,  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)JScrollPane.HORIZONTAL\_SCROLLBAR\_NEVER);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)scroll.getVerticalScrollBar().setUnitIncrement(10);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)scroll.getViewport().add(panel);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)//构建数据列表  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)ListpanelList=makeList();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)//设定监听  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)accordionListenerexr=newaccordionListener()...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)publicvoidaccordionStateChanged(accordionEvente)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)initComponent();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)};  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)for(Iteratorit=panelList.iterator();it.hasNext();)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)AccordionPanelepl=(AccordionPanel)it.next();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)addComponent(epl);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)epl.addaccordionListener(exr);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)//加载滚动条监听  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)scroll.getViewport().addComponentListener(newComponentAdapter()...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)publicvoidcomponentResized(ComponentEvente)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)initComponent();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)});  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)//设定大小  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)label.setPreferredSize(newDimension(200,260));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)scroll.setPreferredSize(newDimension(200,260));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)scroll.setMinimumSize(newDimension(200,260));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)split.setLeftComponent(scroll);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)split.setRightComponent(label);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)split.setDividerSize(1);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)split.setBackground(Color.WHITE);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)add(split,BorderLayout.CENTER);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)publicvoidinitComponent()...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)Rectanglere=scroll.getViewport().getViewRect();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)Insetsins=panel.getInsets();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)intcw=(int)re.getWidth()-ins.left-ins.right-20;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)intch=10;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)Component\[]list=panel.getComponents();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)for(inti=0;i&lt;list.length;i++)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)JComponenttmp=(JComponent)list\[i];  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)intth=tmp.getPreferredSize().height;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)tmp.setPreferredSize(newDimension(cw,th));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)ch=ch+th+10;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)panel.setPreferredSize(newDimension((int)re.getWidth(),ch+ins.top  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)+ins.bottom));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)panel.revalidate();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)publicvoidaddComponent(Componentlabel)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)SpringLayoutlayout=newSpringLayout();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)Component\[]list=panel.getComponents();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)if(list.length==0)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)layout.putConstraint(SpringLayout.WEST,label,10,  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)SpringLayout.WEST,panel);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)layout.putConstraint(SpringLayout.NORTH,label,10,  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)SpringLayout.NORTH,panel);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)}else...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)JComponentcmp=null;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)for(inti=0;i&lt;list.length;i++)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)JComponenttmp=(JComponent)list\[i];  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)layout.putConstraint(SpringLayout.WEST,tmp,10,  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)SpringLayout.WEST,panel);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)if(cmp==null)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)layout.putConstraint(SpringLayout.NORTH,tmp,10,  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)SpringLayout.NORTH,panel);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)}else...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)layout.putConstraint(SpringLayout.NORTH,tmp,10,  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)SpringLayout.SOUTH,cmp);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)cmp=tmp;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)layout.putConstraint(SpringLayout.WEST,label,10,  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)SpringLayout.WEST,panel);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)layout.putConstraint(SpringLayout.NORTH,label,10,  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)SpringLayout.SOUTH,cmp);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)panel.add(label);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)panel.setLayout(layout);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)initComponent();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)privateListmakeList()...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)ListpanelList=newArrayList();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)panelList.add(newAccordionPanel("列表1")...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)/\*\*\*//\**  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)*  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)privatestaticfinallongserialVersionUID=1L;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)publicJPanelmakePanel()...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)JPanelpnl=newJPanel(newGridLayout(0,1));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)JCheckBoxc1=newJCheckBox("aaaaaa");  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)JCheckBoxc2=newJCheckBox("bbbbbb");  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)c1.setOpaque(false);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)c2.setOpaque(false);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)pnl.add(c1);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)pnl.add(c2);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)pnl.setSize(newDimension(0,60));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)pnl.setBorder(BorderFactory.createEmptyBorder(5,15,5,15));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)returnpnl;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)});  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)panelList.add(newAccordionPanel("列表2")...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)/\*\*\*//\**  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)*  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)privatestaticfinallongserialVersionUID=1L;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)publicJPanelmakePanel()...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)JPanelpnl=newJPanel(newGridLayout(0,1));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)pnl.add(newJLabel("辛苦遭逢起一经"));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)pnl.add(newJLabel("干戈寥落四周星"));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)pnl.add(newJLabel("山河破碎风飘絮"));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)pnl.add(newJLabel("身世浮沉雨打萍"));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)pnl.setSize(newDimension(0,100));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)pnl.setBorder(BorderFactory.createEmptyBorder(5,15,5,15));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)returnpnl;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)});  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)panelList.add(newAccordionPanel("列表3")...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)/\*\*\*//\**  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)*  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)privatestaticfinallongserialVersionUID=1L;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)publicJPanelmakePanel()...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)JPanelpnl=newJPanel(newGridLayout(0,1));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)JRadioButtonb1=newJRadioButton("aa");  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)JRadioButtonb2=newJRadioButton("bb");  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)JRadioButtonb3=newJRadioButton("cc");  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)b1.setOpaque(false);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)b2.setOpaque(false);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)b3.setOpaque(false);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)pnl.add(b1);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)pnl.add(b2);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)pnl.add(b3);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)ButtonGroupbg=newButtonGroup();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)bg.add(b1);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)bg.add(b2);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)bg.add(b3);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)b1.setSelected(true);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)pnl.setSize(newDimension(0,80));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)pnl.setBorder(BorderFactory.createEmptyBorder(5,15,5,15));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)returnpnl;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)});  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)returnpanelList;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)publicstaticvoidmain(String\[]args)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)EventQueue.invokeLater(newRunnable()...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)publicvoidrun()...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)createUI();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)});  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)publicstaticvoidcreateUI()...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)JFrameframe=newJFrame("JAVA实现类Windows导航栏");  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)frame.setDefaultCloseOperation(WindowConstants.EXIT\_ON\_CLOSE);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)frame.getContentPane().add(newExampleAccordion());  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)frame.pack();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)frame.setLocationRelativeTo(null);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)frame.setVisible(true);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)classaccordionEventextendsjava.util.EventObject...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)/\*\*\*//\**  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)*  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)privatestaticfinallongserialVersionUID=1L;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)publicaccordionEvent(Objectsource)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)super(source);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)interfaceaccordionListener...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)publicvoidaccordionStateChanged(accordionEvente);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)abstractclassAccordionPanelextendsJPanel...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)abstractpublicJPanelmakePanel();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)privatefinalString\_title;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)privatefinalJLabellabel;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)privatefinalJPanelpanel;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)privatebooleanopenFlag=false;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)publicAccordionPanel(Stringtitle)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)super(newBorderLayout());  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\_title=title;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)label=newJLabel("↓"+title)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)/\*\*\*//\**  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)*  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)privatestaticfinallongserialVersionUID=1L;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)protectedvoidpaintComponent(Graphicsg)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)Graphics2Dg2=(Graphics2D)g;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)//绘制渐变  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)g2.setPaint(newGradientPaint(50,0,Color.WHITE,getWidth(),  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)getHeight(),newColor(199,212,247)));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)g2.fillRect(0,0,getWidth(),getHeight());  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)super.paintComponent(g);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)};  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)label.addMouseListener(newMouseAdapter()...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)publicvoidmousePressed(MouseEventevt)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)openFlag=!openFlag;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)initPanel();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)fireaccordionEvent();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)});  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)label.setForeground(newColor(33,93,198));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)label.setFont(newFont("宋体",1,12));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)label.setBorder(BorderFactory.createEmptyBorder(2,5,2,2));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)panel=makePanel();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)panel.setOpaque(true);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)BorderoutBorder=BorderFactory.createMatteBorder(0,2,2,2,  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)Color.WHITE);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)BorderinBorder=BorderFactory.createEmptyBorder(10,10,10,10);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)Borderborder=BorderFactory.createCompoundBorder(outBorder,inBorder);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)panel.setBorder(border);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)panel.setBackground(newColor(240,240,255));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)add(label,BorderLayout.NORTH);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)publicbooleanisSelected()...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)returnopenFlag;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)publicvoidsetSelected(booleanflg)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)openFlag=flg;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)initPanel();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)protectedvoidinitPanel()...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)if(isSelected())...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)label.setText("↑"+\_title);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)add(panel,BorderLayout.CENTER);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)setPreferredSize(newDimension(getSize().width,  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)label.getSize().height+panel.getSize().height));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)}else...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)label.setText("↓"+\_title);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)remove(panel);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)setPreferredSize(newDimension(getSize().width,  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)label.getSize().height));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)revalidate();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)protectedArrayListaccordionListenerList=newArrayList();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)publicvoidaddaccordionListener(accordionListenerlistener)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)if(!accordionListenerList.contains(listener))  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)accordionListenerList.add(listener);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)publicvoidremoveaccordionListener(accordionListenerlistener)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)accordionListenerList.remove(listener);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)publicvoidfireaccordionEvent()...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)Listlist=(List)accordionListenerList.clone();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)Iteratorit=list.iterator();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)accordionEvente=newaccordionEvent(this);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)while(it.hasNext())...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)accordionListenerlistener=(accordionListener)it.next();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)listener.accordionStateChanged(e);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

效果图：  
![](http://p.blog.csdn.net/images/p_blog_csdn_net/cping1982/swingpan.gif)