jpanel.setPreferredSize(int x,int y)

解决方案 »

  1.   

    很简单呀,将JFrame容器蛇成x,y坐标系统以后,JPanel你想设成多少就设成多少。最简单的方法,拿鼠标拖就是了。
      

  2.   

    jdbcodbcPanel = new JPanel();
       contentPanel.setLayout(new BorderLayout());
               JLabel label1 = new JLabel("username");
       JLabel label2 = new JLabel("password");
       JLabel label3 = new JLabel("sex");
       JLabel label4 = new JLabel("location");
               JTextField TextUser = new JTextField("");
               JTextField TextPassword = new JTextField("");
               JTextField TextSex = new JTextField("");
               JTextField TextLocation = new JTextField("");
       TextUser.setColumns(10);
       TextPassword.setColumns(10);
       TextSex.setColumns(10);
       TextLocation.setColumns(10);
       jdbcodbcPanel.add(label1);
       jdbcodbcPanel.add(TextUser);
       jdbcodbcPanel.add(label2);
       jdbcodbcPanel.add(TextPassword);
       jdbcodbcPanel.add(label3);
       jdbcodbcPanel.add(TextSex);
       jdbcodbcPanel.add(label4);
       jdbcodbcPanel.add(TextLocation);    contentPanel.add(jdbcodbcPanel,BorderLayout.WEST);
    所有控件并排,怎样换行?
      

  3.   

    jdbcodbcPanel 没有使用layout , 要使用某个layout来布局的
    然后在用相应的add方法
      

  4.   

    JFrame frame=new JFrame("mainFrame");
    frame.setLayout(new FlowLayout());
      

  5.   

    也可以用绝对坐标来布局的
    setLayout(null);
    然后每一个控件都要绑定位置
    用setBounds(int x, int y, int width, int height);
    然后直接add就好了
    也蛮方便的VAJ就是这样做的
    xyLayout是borland自己搞的