2012-08-01 89 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