资源简介
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 < list.length; 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 < list.length; 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
相关资源
- JSP+MYSQL旅行社管理信息系统
- 推荐算法的JAVA实现
- 基于Java的酒店管理系统源码(毕业设
- java-图片识别 图片比较
- android毕业设计
- java23种设计模式+23个实例demo
- java Socket发送/接受报文
- JAVA828436
- java界面美化 提供多套皮肤直接使用
- 在线聊天系统(java代码)
- 基于Java的图书管理系统807185
- java中实现将页面数据导入Excel中
- java 企业销售管理系统
- java做的聊天系统(包括正规课程设计
- Java编写的qq聊天室
- 商店商品管理系统 JAVA写的 有界面
- JAVA开发聊天室程序
- 在linux系统下用java执行系统命令实例
- java期末考试试题两套(答案) 选择(
- JAVA3D编程示例(建模、交互)
- Java 文件加密传输
- java做的房产管理系统
- 基于jsp的bbs论坛 非常详细
- [免费]java实现有障碍物的贪吃蛇游戏
- java Servlet投票实例
- 操作系统作业 (pv,作业管理,等5个
- 基于C/S架构考试系统(Java)
- java access 仓库管理系统 源码
- 一元多项式相加 java实现
- java软件工程师简历模板——应届生
评论
共有 条评论