2012-08-01 97 views
0

我在ScrollPane中有一個jList,當我調整我的框架時,它的行爲很奇怪。 通常是這樣的: Before 我成長表左側水平後,我的jList變成這樣: AfterJList水平調整大小導致垂直縮小

我張貼的GUI的一些代碼,可能會有所幫助:

scrlInterfaceList.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); 
    scrlInterfaceList.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); 

    //---- list1 ---- 
    lstInterfaces.setBorder(BorderFactory.createTitledBorder(LFwPolicyMaker.messages.getString("IpMacMatcher.MatchTab.controlPanel.interfaces.title"))); 
    lstInterfaces.setPreferredSize(null); 
    lstInterfaces.setMaximumSize(new Dimension(55, 90)); 
    lstInterfaces.setMinimumSize(new Dimension(55, 90)); 

    lstInterfaces.setLayoutOrientation(JList.VERTICAL); 
    lstInterfaces.setModel(new AbstractListModel() { 

     String[] strings = getInterfaces(); 

     public int getSize() { 
      return strings.length; 
     } 

     public Object getElementAt(int i) { 
      return strings[i]; 
     } 
    }); 
    scrlInterfaceList.setViewportView(lstInterfaces); 

    setSelectedInterfaces(); 

    add(scrlInterfaceList,new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, 
       GridBagConstraints.CENTER, GridBagConstraints.BOTH, 
       new Insets(0, 0, 0, 0), 0, 0)); 

可能是什麼問題?我想要的jList繼續上述

水平萎縮,如組合框,按鈕
+1

*「我張貼,這可能是有幫助的GUI的一些代碼: 「*爲了更快得到更好的幫助,請發佈[SSCCE](http://sscce.org/)。 – 2012-08-01 11:10:03

+1

嘗試將GridBagConstraints的權重值設置爲1.0,以使工作感謝的滾動窗格 – MadProgrammer 2012-08-01 11:12:09

+0

@MadProgrammer。也許你應該添加它作爲答案,而不是評論。 – Alptugay 2012-08-01 11:28:16

回答

4

嘗試使用滾動窗格中的GridBagConstraints份量的值設置爲1.0