• 大小: 25KB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2021-05-10
  • 语言: Java
  • 标签: Java  Swing  折叠菜单  

资源简介

精美的Java Swing折叠菜单,完全模仿window xp左边的折叠菜单做的,拥有超炫动态效果,值得珍藏! 解压后,在eclipse里面编译后直接运行FolderPaneDemo类。

资源截图

代码片段和文件信息

/*
 * CaptionButton.java
 *
 * Created on June 8 2007 5:34 PM
 *
 * To change this template choose Tools | Template Manager
 * and open the template in the editor.
 */

package dyno.swing.beans;

import java.awt.ItemSelectable;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import javax.swing.JComponent;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;

/**
 * 该组件是折叠面板的标题栏组件。这是一个类似toggle-button的组件。
 *
 * @author William Chen
 * @mail rehte@hotmail.com
 */
public class CaptionButton extends JComponent implements ItemSelectable{
    // 事件处理器集合
    private ArrayList listeners=new ArrayList();
    
    //是否展开
    private boolean expanded;
    //标题文字
    private String text;
    
    
    /** Creates a new instance of CaptionButton */
    public CaptionButton(){
        this(null true);
    }
    
    /**
     * @param text 标题
     * @expanded 目前是否展开
     */
    public CaptionButton(String text boolean expanded) {
        this.text=text;
        this.expanded=expanded;
        setUI(new CaptionButtonUI());
    }
    //添加选择事件处理器
    public void addItemListener(ItemListener l){
        if(!listeners.contains(l))
            listeners.add(l);
    }
    //删除选择事件处理器
    public void removeItemListener(ItemListener l){
        if(listeners.contains(l))
            listeners.remove(l);
    }
    //触发事件处理器
    protected void fireItemStateChanged(ItemEvent e){
        for(ItemListener l:listeners)
            l.itemStateChanged(e);
    }
    //
    public object[] getSelectedobjects() {
        if(!expanded)
            return null;
        return new object[]{text};
    }    
    public boolean isExpanded() {
        return expanded;
    }    
    public void setExpanded(boolean expanded) {
        this.expanded = expanded;
        repaint();
    }    
    public String getText() {
        return text;
    }    
    public void setText(String text) {
        this.text = text;
        repaint();
    } 
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2012-11-26 19:32  foldered_pane\
     目录           0  2012-11-26 19:32  foldered_pane\src\
     目录           0  2012-11-26 19:32  foldered_pane\src\dyno\
     目录           0  2012-11-26 19:32  foldered_pane\src\dyno\swing\
     目录           0  2012-11-26 19:32  foldered_pane\src\dyno\swing\beans\
     文件        2182  2007-06-09 12:15  foldered_pane\src\dyno\swing\beans\CaptionButton.java
     文件        7404  2007-06-09 12:16  foldered_pane\src\dyno\swing\beans\CaptionButtonUI.java
     文件        2362  2007-06-09 12:16  foldered_pane\src\dyno\swing\beans\Drawer.java
     文件        2698  2007-06-09 12:16  foldered_pane\src\dyno\swing\beans\Folder.java
     文件        3797  2007-06-10 17:12  foldered_pane\src\dyno\swing\beans\FolderPane.java
     文件        5788  2007-06-10 17:14  foldered_pane\src\dyno\swing\beans\FolderPaneUI.java
     目录           0  2012-11-26 19:32  foldered_pane\src\dyno\swing\beans\resources\
     文件         636  2007-06-09 03:24  foldered_pane\src\dyno\swing\beans\resources\expanded.png
     文件         701  2007-06-09 03:24  foldered_pane\src\dyno\swing\beans\resources\foldered.png
     文件         633  2007-06-09 03:24  foldered_pane\src\dyno\swing\beans\resources\hovered_expanded.png
     文件         640  2007-06-09 03:24  foldered_pane\src\dyno\swing\beans\resources\hovered_foldered.png
     目录           0  2012-11-26 19:32  foldered_pane\src\dyno\swing\beans\test\
     文件        3782  2007-06-10 17:11  foldered_pane\src\dyno\swing\beans\test\FolderPaneDemo.java
     文件        2257  2007-06-09 12:17  foldered_pane\src\dyno\swing\beans\test\ListPane.java
     文件         570  2007-06-09 03:24  foldered_pane\src\dyno\swing\beans\test\drive.png
     文件         766  2007-06-09 03:24  foldered_pane\src\dyno\swing\beans\test\internet.png
     文件         683  2007-06-09 03:24  foldered_pane\src\dyno\swing\beans\test\mycom.png
     文件         539  2007-06-09 03:24  foldered_pane\src\dyno\swing\beans\test\mydoc.png
     文件         823  2007-06-09 03:24  foldered_pane\src\dyno\swing\beans\test\neighbor.png
     文件         815  2007-06-09 03:24  foldered_pane\src\dyno\swing\beans\test\newfolder.png
     文件         736  2007-06-09 03:24  foldered_pane\src\dyno\swing\beans\test\share.png
     文件         502  2007-06-09 03:24  foldered_pane\src\dyno\swing\beans\test\shareddoc.png
     文件         520  2007-06-09 03:24  foldered_pane\src\dyno\swing\beans\test\title.png

评论

共有 条评论