資源簡介
JAVA SWING可折疊菜單

代碼片段和文件信息
import?java.util.ArrayList;
import?java.util.Iterator;
import?java.util.List;
import?java.awt.*;
import?javax.swing.*;
import?java.awt.event.*;
import?javax.swing.border.Border;
public?class?ExampleAccordion?extends?JPanel?{
private?static?final?long?serialVersionUID?=?1L;
private?final?JPanel?panel?=?new?JPanel();
private?final?JLabel?label?=?new?JLabel();
private?final?JSplitPane?split?=?new?JSplitPane();
private?final?JScrollPane?scroll;
????public?ExampleAccordion()?{
???? super(new?BorderLayout());
???? panel.setOpaque(true);
???? panel.setBackground(new?Color(116?149?226));
???? scroll?=?new?JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED
???? JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
???? scroll.getVerticalScrollBar().setUnitIncrement(10);
???? scroll.getViewport().add(panel);
???? List?panelList?=?makeList();
???? accordionListener?exr?=?new?accordionListener()?{
???? public?void?accordionStateChanged(accordionEvent?e)?{
???? initComponent();
???? }
???? };
???? for?(Iterator?it?=?panelList.iterator();?it.hasNext();)?{
???? AccordionPanel?epl?=?(AccordionPanel)?it.next();
???? addComponent(epl);?epl.addaccordionListener(exr);
???? }
???? scroll.getViewport().addComponentListener(new?ComponentAdapter()?{
???? public?void?componentResized(ComponentEvent?e)?{
???? initComponent();
???? }
???? });
???? label.setPreferredSize(new?Dimension(200?260));
???? scroll.setPreferredSize(new?Dimension(200?260));
???? scroll.setMinimumSize(new?Dimension(200?260));
???? split.setLeftComponent(scroll);
???? split.setRightComponent(label);
???? split.setDividerSize(1);
???? split.setBackground(Color.WHITE);
???? add(split?BorderLayout.CENTER);
???? }
????
????public?void?initComponent()?{
???? Rectangle?re?=?scroll.getViewport().getViewRect();
???? Insets?ins?=?panel.getInsets();
???? int?cw?=?(int)?re.getWidth()?-?ins.left?-?ins.right?-?20;
???? int?ch?=?10;
???? Component[]?list?=?panel.getComponents();
???? for?(int?i?=?0;?i????? JComponent?tmp?=?(JComponent)?list[i];
???? int?th?=?tmp.getPreferredSize().height;
???? tmp.setPreferredSize(new?Dimension(cw?th));
???? ch?=?ch?+?th?+?10;
???? }
???? panel.setPreferredSize(new?Dimension((int)?re.getWidth()?ch?+?ins.top?+?ins.bottom));
???? panel.revalidate();
???? }
????
????public?void?addComponent(Component?label)?{
???? SpringLayout?layout?=?new?SpringLayout();
???? Component[]?list?=?panel.getComponents();
???? if?(list.length?==?0)?{
???? layout.putConstraint(SpringLayout.WEST?label?10?SpringLayout.WEST?panel);
???? layout.putConstraint(SpringLayout.NORTH?label?10?SpringLayout.NORTH?panel);
???? }?else?{
???? JComponent?cmp?=?null;
???? for?(int?i?=?0;?i????? JComponent?tmp?=?(JComponent)?list[i];
???? layout.putConstraint(SpringLayout.WEST?tmp?10?SpringLayout.WEST?panel);
???? if?(cmp
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????301??2013-04-15?16:38??SWING可折疊菜單\.classpath
?????文件????????396??2013-04-15?16:38??SWING可折疊菜單\.project
?????文件????????629??2013-04-15?16:38??SWING可折疊菜單\.settings\org.eclipse.jdt.core.prefs
?????文件????????401??2013-04-15?17:05??SWING可折疊菜單\bin\accordionEvent.class
?????文件????????168??2013-04-15?17:05??SWING可折疊菜單\bin\accordionListener.class
?????文件???????1149??2013-04-15?17:05??SWING可折疊菜單\bin\AccordionPanel$1.class
?????文件????????880??2013-04-15?17:05??SWING可折疊菜單\bin\AccordionPanel$2.class
?????文件???????4147??2013-04-15?17:05??SWING可折疊菜單\bin\AccordionPanel.class
?????文件????????637??2013-04-15?17:05??SWING可折疊菜單\bin\ExampleAccordion$1.class
?????文件????????652??2013-04-15?17:05??SWING可折疊菜單\bin\ExampleAccordion$2.class
?????文件???????1412??2013-04-15?17:05??SWING可折疊菜單\bin\ExampleAccordion$3.class
?????文件???????1342??2013-04-15?17:05??SWING可折疊菜單\bin\ExampleAccordion$4.class
?????文件???????1678??2013-04-15?17:05??SWING可折疊菜單\bin\ExampleAccordion$5.class
?????文件????????516??2013-04-15?17:05??SWING可折疊菜單\bin\ExampleAccordion$6.class
?????文件???????5356??2013-04-15?17:05??SWING可折疊菜單\bin\ExampleAccordion.class
?????文件???????9132??2013-04-15?17:05??SWING可折疊菜單\src\ExampleAccordion.java
?????目錄??????????0??2013-04-15?16:38??SWING可折疊菜單\.settings
?????目錄??????????0??2013-04-15?17:00??SWING可折疊菜單\bin
?????目錄??????????0??2013-04-15?17:00??SWING可折疊菜單\src
?????目錄??????????0??2013-04-15?16:38??SWING可折疊菜單
-----------?---------??----------?-----??----
????????????????28796????????????????????20
評論
共有 條評論