<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    JAVA進行式
    讓我們把JAVA進行到底!
    posts - 13,comments - 21,trackbacks - 0

            工具欄ToolBar中可加入如JLabel、JPanel、JButton或JComboBox等很多可視化組件的對象,且默認為FlowLayout布局管理器,有時候因為編程的需要,我們要往里面插入很多個組件,如何顯示出完整的組件列表成了一個問題,而ToolBar的對象放在JScrollPane對象中是顯示不出來的,原因是它和JPanel一樣是沒有邊框的,我的解決辦法是,將要插入到工具欄的對象先放入集合中(如果全是相同類型的對象,放在數組中保存更好),再通過for循環依次加入到ToolBar對象中,在ToolBar外面設置一個按鈕,編寫響應該按鈕的點擊事件,當該按鈕被點擊一次時,通過數組下標(或集合索引)從ToolBar中remove()去掉一個組件,并調用revalidate()方法,讓緊跟其后的組件移上去,添補刪除后留下的空白,并把刪除的那個組件重新用add()方法追加到工具欄尾部,這樣循環刪除和添加,就實現了工具欄的滾動效果,由于工具欄的FlowLayout布局,使它在未設置時只能向一個方向添加組件,故我的這個工具欄的滾動效果是單向的。
            對于兩向滾動,我考慮在反向滾動前重新設置工具欄的布局管理器,以改變其添加組件的方向,從而達到雙向滾動的效果。具體能否實現,有待進一步編碼檢測。
            在這里我把單向滾動的源代碼記錄如下:

    /**DiaryEditToolBarPane類構建一個包含一個工具欄和一個控制滾動的按鈕 */

    public class DiaryEditToolBarPane extends JPanel implements ActionListener
    {
     JTextPane jTextPane;
     DiaryEditToolBar diaryEditToolBar;
     JPanel jPanelSouth = new JPanel();
     JButton jButtonUp = new JButton(ConstValue.IMG_UP);
     //JButton jButtonDn = new JButton(ConstValue.IMG_DN);
     
     public DiaryEditToolBarPane(JTextPane jTextPane)
     {
      this.jTextPane = jTextPane;
      diaryEditToolBar = new DiaryEditToolBar(this.jTextPane);
      
      jButtonUp.setMargin(new Insets(0,0,0,0));
      //jButtonDn.setMargin(new Insets(0,0,0,0));
      jButtonUp.setActionCommand("up");
      //jButtonDn.setActionCommand("down");
      //jPanelSouth.setLayout(new GridLayout(2,1));
      jPanelSouth.add(jButtonUp);
      //jPanelSouth.add(jButtonDn);
      
      this.setLayout(new BorderLayout());
      this.add(diaryEditToolBar,BorderLayout.CENTER);
      this.add(jPanelSouth, BorderLayout.SOUTH);
      
      jButtonUp.addActionListener(this);
      //jButtonDn.addActionListener(this);
     }
      
     public void setTextPane(JTextPane jTextPane)
     {
      this.jTextPane = jTextPane;
      diaryEditToolBar.setTextPane(this.jTextPane);
     }

     public void actionPerformed(ActionEvent e)
     {
      if(e.getActionCommand().equals("up"))
      {
       diaryEditToolBar.moveUp();
      }
      /*
      else if(e.getActionCommand().equals("down"))
      {
       diaryEditToolBar.moveDown(); 
      }*/
     }
    }

    /**定義一個具體實現工具欄組件布局與滾動的類DiaryEditToolBar  */

    public class DiaryEditToolBar extends JToolBar
    {
     /**用于保存工具按鈕的對象數組*/
     private BrimlessButton[] toolBarButton;
     /**工具按鈕增、刪索引值*/
     private static int index = 0;
     
      
     private void init()
     {
      this.setFloatable(false);
      BrimlessButton[] temp =
      {
       toolBarButtonSave,toolBarButtonSave,toolBarButtonCut,
       toolBarButtonCopy,toolBarButtonPaste,toolBarButtonFontStyle,
       toolBarButtonFontSize,toolBarButtonFontForeground,toolBarButtonBackground,
       toolBarButtonBold,toolBarButtonItalic,toolBarButtonUnderline,
       toolBarButtonFlusLeft,toolBarButtonCenter,toolBarButtonFlushRight,
       toolBarButtonUndo,toolBarButtonRedo,toolBarButtonIndentLeft,
       toolBarButtonIndentRight,toolBarButtonURL,toolBarButtonImage,
       toolBarButtonDateTime
      };
      toolBarButton = temp;
      
      for(int i=0; i<22; i++)
      {
       this.addElement(toolBarButton[i]);
      }

     }

     private void addElement(JButton jButton)
     {
      this.add(jButton);
     }
     
     private void delElement(JButton jButton)
     { 
      this.remove(jButton);
     }
     
     /**刪除工具欄開頭的工具按鈕,并將其添加到工具欄末尾,以實現工具欄向上滾動的效果*/
     public void moveUp()
     {
      delElement(toolBarButton[index]);
      this.revalidate();
      addElement(toolBarButton[index]);
      index = (++index)%22;
     }
     
     /**增加工具欄開頭的工具按鈕,以實現工具欄向下滾動的效果*/
     public void moveDown()
     {
      //addElement(toolBarButton[index]);
      //this.revalidate();
      //repaint();
     } 
    }

    posted on 2005-11-29 23:18 水秀清靈 閱讀(1185) 評論(0)  編輯  收藏 所屬分類: 學習筆記
    主站蜘蛛池模板: 久久午夜伦鲁片免费无码| 黄视频在线观看免费| 亚洲一区二区三区免费视频| 亚洲色欲久久久综合网| 久久最新免费视频| 亚洲夜夜欢A∨一区二区三区| 亚洲一级片免费看| 亚洲AV一宅男色影视| 日本免费人成网ww555在线| 久久亚洲日韩精品一区二区三区| 蜜桃视频在线观看免费视频网站WWW| 亚洲成在人线av| h视频在线免费看| 久久亚洲精品国产精品婷婷 | 亚洲日韩AV一区二区三区四区| 日韩精品成人无码专区免费| 亚洲中文精品久久久久久不卡| 四虎www免费人成| 无码 免费 国产在线观看91| 久久亚洲AV永久无码精品| 久艹视频在线免费观看| 亚洲视频国产精品| 麻豆国产入口在线观看免费| 一级A毛片免费观看久久精品 | 亚洲国产成人片在线观看无码| 69精品免费视频| 亚洲日韩一区二区一无码| 深夜国产福利99亚洲视频| 三级黄色片免费看| 亚洲人成电影院在线观看| 国产精品色午夜视频免费看| 国产免费牲交视频免费播放 | 亚洲人成网77777色在线播放| 免费观看激色视频网站bd| 精品女同一区二区三区免费播放| 亚洲精品二区国产综合野狼| 99久久免费国产香蕉麻豆| 天天综合亚洲色在线精品| 亚洲电影免费在线观看| 爽爽日本在线视频免费| 暖暖免费日本在线中文|