如题

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【happyandsad】截止到2008-07-10 15:38:34的历史汇总数据(不包括此帖):
    发帖的总数量:18                       发帖的总分数:989                      每贴平均分数:54                       
    回帖的总数量:251                      得分贴总数量:82                       回帖的得分率:32%                      
    结贴的总数量:17                       结贴的总分数:923                      
    无满意结贴数:1                        无满意结贴分:20                       
    未结的帖子数:1                        未结的总分数:66                       
    结贴的百分比:94.44 %               结分的百分比:93.33 %                  
    无满意结贴率:5.88  %               无满意结分率:2.17  %                  
    值得尊敬
      

  2.   

    使用GridBagLayout,设置 1 列 n+1 行的网格,n 为所有按钮的个数,包括扩充出来的按照顺序依次将每个按钮放在第i个网格上,隐藏暂时不需要显示的,第n+1个网格放个JLabel
    啥的设置填充方式为双方向,主要是为了消耗掉剩余的空间,点击 第i个按钮的时候将本来隐藏的
    设置为可见,其它本来隐藏的设置为隐藏就可以了
      

  3.   

    晓得了,Lz说的这个组件叫Outlook Bar,我自个写过,网上也能查到其它人的源码。例如:
    http://www.java2s.com/Code/Java/Swing-Components/OutlookBarSourceCode.htm
      

  4.   

    再给你个简单示例,100分,呵呵。
    import java.awt.Component;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;public class Test extends JFrame implements ActionListener{
    public Test(){
    setSize(200,400);
    setLayout(null);
    JPanel p = new JPanel();
    p.setBounds(10,10,80,350);
    add(p);
    p.setLayout(new GridBagLayout());
    Insets is = new Insets(1,1,1,1);
    JButton b = new JButton("test 1");
    p.add(b,new GridBagConstraints(0,0,1,1,1,0,GridBagConstraints.WEST,GridBagConstraints.HORIZONTAL,is,0,0));
    b.addActionListener(this);
    b = new JButton("sub test 11");
    b.setVisible(false);
    p.add(b,new GridBagConstraints(0,1,1,1,1,0,GridBagConstraints.WEST,GridBagConstraints.HORIZONTAL,is,0,0));
    b = new JButton("sub test 12");
    b.setVisible(false);
    p.add(b,new GridBagConstraints(0,2,1,1,1,0,GridBagConstraints.WEST,GridBagConstraints.HORIZONTAL,is,0,0));
    b = new JButton("sub test 13");
    b.setVisible(false);
    p.add(b,new GridBagConstraints(0,3,1,1,1,0,GridBagConstraints.WEST,GridBagConstraints.HORIZONTAL,is,0,0));
    b = new JButton("test 2");
    b.addActionListener(this);
    p.add(b,new GridBagConstraints(0,4,1,1,1,0,GridBagConstraints.WEST,GridBagConstraints.HORIZONTAL,is,0,0));
    b = new JButton("sub test 21");
    p.add(b,new GridBagConstraints(0,5,1,1,1,0,GridBagConstraints.WEST,GridBagConstraints.HORIZONTAL,is,0,0));
    b.setVisible(false);
    b = new JButton("sub test 22");
    p.add(b,new GridBagConstraints(0,6,1,1,1,0,GridBagConstraints.WEST,GridBagConstraints.HORIZONTAL,is,0,0));
    b.setVisible(false);
    b = new JButton("sub test 23");
    b.setVisible(false);
    p.add(b,new GridBagConstraints(0,7,1,1,1,0,GridBagConstraints.WEST,GridBagConstraints.HORIZONTAL,is,0,0));
    b = new JButton("exit");
    b.addActionListener(this);
    p.add(b,new GridBagConstraints(0,8,1,1,1,0,GridBagConstraints.WEST,GridBagConstraints.HORIZONTAL,is,0,0));
    JLabel lb = new JLabel();
    p.add(lb,new GridBagConstraints(0,9,1,1,1,1,GridBagConstraints.WEST,GridBagConstraints.BOTH,is,0,0));
    }
    public void actionPerformed(ActionEvent e){
    JButton b = (JButton)e.getSource();
    if(b.getText().equals("test 1")){
    Component[] objects = b.getParent().getComponents();
    for(int i=0;i<objects.length;i++){
    if( objects[i] instanceof JButton){
    JButton bt = (JButton)objects[i];
    if ( bt.getText().startsWith("sub test 1")){
    bt.setVisible(!bt.isVisible());
    }else if ( bt.getText().startsWith("sub test 2")){
    bt.setVisible(false);
    }
    }
    }
    }else if(b.getText().equals("test 2")){
    Component[] objects = b.getParent().getComponents();
    for(int i=0;i<objects.length;i++){
    if( objects[i] instanceof JButton){
    JButton bt = (JButton)objects[i];
    if ( bt.getText().startsWith("sub test 2")){
    bt.setVisible(!bt.isVisible());
    }else if ( bt.getText().startsWith("sub test 1")){
    bt.setVisible(false);
    }
    }
    }
    }else if(b.getText().equals("exit")){
    System.exit(0);
    }
    }
    public static void main(String[] args){
    Test t = new Test();
    t.setVisible(true);
    }
    }
      

  5.   

    试了下楼上的效果,和OutlookBar比在外观效果还是有差距,关键是要用JList。
    并且不具备可定制性和可扩展性,内容都是写死的,不能随意插入选择和内容面板。
      

  6.   

    使用卡片布局  cardLayout
      

  7.   


    只是个简单的示例啊!而且没用JList哦,如果是要写成可用的东西的代码是这个样子
    而且无法扩展的话,俺早就自己投河自尽了。关键是要了解其思想,至少是怎样实现的,而且实现方法本来就不会只有一个。
    如果一开始就用别人的jar包的话,就失去了学习的机会啦。扩展方案:扩充JButton等,支持多语言和外观,可采用xml定制,自动生成工具条,呵呵。
      

  8.   

    以前使用SWT写了一个。
    但是重装系统找不到源码了 。。
      

  9.   

    老三你比较捧场啊
    谢谢了啊
    好用的和我想的效果一样 
    favorite7w 和阿修罗都是可以用的,哥们100分我就平分了行吗呵呵