日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
控件位置可以配置的Swing桌面

用過Wordpress或者Joomla的朋友一定對他們的靈活的頁面布局印象深刻。在Joomla中,你可以將一個(gè)控件,放在頁面的任何一個(gè)位置,例如:左邊,右邊,菜單,底部等等。

所以我也嘗試著在Swing桌面上實(shí)現(xiàn)類似的功能,思考以后發(fā)現(xiàn)其實(shí)swing實(shí)現(xiàn)這種功能比利用html頁面實(shí)現(xiàn)該功能還簡單。

首先我們定義一個(gè)位置接口,實(shí)現(xiàn)該接口的類就標(biāo)示它的位置

 
 
 
 
  1. public interface Arrange {  
  2.       
  3.     public String getComponentName();  
  4.  

第二:繼承Arrange 接口,定義不用的位置接口,分別有

 
 
 
 
  1. public interface ArrangeBottom extends Arrange  
  2. public interface ArrangeLeft extends Arrange  
  3. public interface ArrangeLogo extends Arrange  
  4. public interface ArrangeMainBottom extends Arrange  
  5. public interface ArrangeMenuBar extends Arrange  
  6. public interface ArrangeRight extends Arrange  
  7. public interface ArrangeToolBar extends Arrange  

上面的接口標(biāo)示的位置見下圖:

第三:我們寫一個(gè)面板,實(shí)現(xiàn)位置接口

例如:public class ZPanel extends JPanel implements ArrangeRight

 
 
 
 
  1. protected void paintComponent(Graphics g) {  
  2.         if (null != wallpaper) {  
  3.             processBackground(g);  
  4.         }  
  5.         System.out.println("f:paintComponent(Graphics g)");  
  6.     }  
  7.  
  8.     public void setBackground() {  
  9.         wallpaper = new javax.swing.ImageIcon(getClass()  
  10.                 .getResource("/com/peraglobal/workspace/initcompt/picpanel/kutoku.jpg"));  
  11.         this.repaint();  
  12.     }  

第四:在配置文件中配置這個(gè)類

打開配置文件按zlconfig.xml

編寫

第五:加載配置文件

我們利用Spring將配置文件中實(shí)現(xiàn)了某一接口的類全部拿出,并且加載到指定的位置:

 
 
 
 
  1. Map lefts = context.getBeansOfType(ArrangeLeft.class);  
  2.         ArrangeLeft agLeft;  
  3.  
  4.         leftPanel.setLayout(new BorderLayout());  
  5.         JTabbedPane tabLeft = new JTabbedPane();  
  6.  
  7.         leftPanel.add(tabLeft);  
  8.  
  9.         Iterator it = lefts.entrySet().iterator();  
  10.         while (it.hasNext()) {  
  11.             Map.Entry entry = (Map.Entry) it.next();  
  12.             Object key = entry.getKey();  
  13.  
  14.             Class newClass = Class.forName((String) key);  
  15.             agLeft = (ArrangeLeft) newClass.newInstance();  
  16.             tabLeft.add((Component) agLeft, agLeft.getComponentName());  
  17.         }  

第六:我們看到我們剛才寫的一個(gè)Panel已經(jīng)加載到了右邊的面板中


當(dāng)前文章:控件位置可以配置的Swing桌面
文章路徑:http://www.dlmjj.cn/article/dhdgose.html