我在设计用户界面的时候遇到了一个问题:
panelquery.setLayout(new GridLayout(3,1));  
JPanel panel1
JComboBox  box;
panel1.add(box);
panelquery.add(panel1);JPanel panel2;  
JButton    button;
panel2.add(button);  
panelquery.add(panel2); 
  我创建的JComboBox实例box用来显示一个列表,其正下方有一个JButton实例button 
在box下拉时,本该显示的数据被button实例挡住了,那位高手帮忙解决一下。 我搜索过以前有这样的例子,解决办法是放在不同的JPanel中
但是现在我两个控件本身就放在不同的JPanel中。
请教如何解决

解决方案 »

  1.   

    我怎么看到的是下拉框挡住了按钮啊, 你是怎么做的, 整个代码贴出来:
    import java.awt.GridLayout;import javax.swing.*;public class TestGUI extends JFrame {

    public TestGUI() {
    this.setBounds(300, 300, 300, 300);

    JPanel panelquery = new JPanel();
    panelquery.setLayout(new GridLayout(3,1));  
    JPanel panel1 = new JPanel();
    String[] strs = {"123", "456", "456", "1234"};
    JComboBox box = new JComboBox(strs);
    panel1.add(box);
    panelquery.add(panel1); JPanel panel2 = new JPanel();  
    JButton button = new JButton("BUTTON");
    panel2.add(button);  
    panelquery.add(panel2);
    this.getContentPane().add(panelquery);
    this.setVisible(true);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    new TestGUI();
    }}
      

  2.   

    整个程序太长,我就贴这一段代码。panelquery.setLayout(new GridLayout(3,1));
    Panel panel11=new Panel(new FlowLayout(FlowLayout.LEFT));
    Container box1=Box.createHorizontalBox();
    panel11.add(box1);
    panelquery.add(panel11);

    Panel panel12=new Panel(new FlowLayout(FlowLayout.LEFT));
    Container box2=Box.createHorizontalBox();
    box2.add(new JButton("In the 2"));

    Vector anclass=new Vector();

    Vector nclass1=new Vector();

    nclass1.add("nclass11[11]");
    nclass1.add("nclass12[12]");
    ComboBoxItem item1=new ComboBoxItem(nclass1,"anclass1[1]");
    anclass.add(item1);

    Vector nclass2=new Vector();

    nclass2.add("nclass21[21]");
    nclass2.add("nclass22[22]");
    ComboBoxItem item2=new ComboBoxItem(nclass2,"anclass2[2]");
    anclass.add(item2);

    Vector nclass3=new Vector();

    nclass3.add("nclass31[31]");
    nclass3.add("nclass32[32]");
    ComboBoxItem item3=new ComboBoxItem(nclass3,"anclass3[3]");
    anclass.add(item3);

    anclassModel=new DefaultComboBoxModel(anclass);
    jComanclass=new JComboBox(anclassModel);
    box2.add(jComanclass);

    Vector nclass=new Vector();
    nclass.add("All");
    nclassModel=new DefaultComboBoxModel(nclass);
    jComnclass=new JComboBox(nclassModel);     

    box2.add(jComnclass);
    panel12.add(box2);

    panelquery.add(panel12);
    Panel panel13=new Panel(new FlowLayout(FlowLayout.LEFT));
    Container box3=Box.createHorizontalBox();
    JButton jButton3=new JButton("get table data");
    JButton jButton4=new JButton("collect column");
    box3.add(jButton3);
    box3.add(jButton4);
    panel13.add(box3);
    panelquery.add(panel13);
      

  3.   

    我现在把Panel3这个面板(就是我的列表框下面的面板)拿掉,就显示正常了。
      

  4.   

    Panel用错了, 应该用JPanel. 
    具体原因看看这篇文章吧:http://www.csdn.net/develop/author/cxy/zorder.shtm