jpanel2.setLayout(new FlowLayout());
改为
jpanel2.setLayout(new BorderLayout());下面的
jpanel2.add(sp);
改为
jpanel2.add(sp,BorderLayout.CENTER);

解决方案 »

  1.   

    修改后的代码:
    package untitled1;import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.io.File;
    import javax.swing.table.*;
    import java.util.*;
    import javax.swing.border.*;public class ReportDataCreat extends JFrame {  private JLabel label1=new JLabel("报表格式文件");
      private JLabel label2=new JLabel("文件保存到");
      private JButton button1=new JButton("浏览");
      private JButton button2=new JButton("浏览");
      private JButton button3=new JButton("报表数据生成并显示");
      private JButton button4=new JButton("报表数据生成并保存");
      private JTextField text1=new JTextField(10);
      private JTextField text2=new JTextField(10);
      private Vector vect;//声明一个向量对象
      private JTable table=new JTable();
      private String title[]={"条件提示","条件值"};
      AbstractTableModel tm;//定义一个数据表模型变量
      private JPanel jpanel1=new JPanel();
      private JPanel jpanel2=new JPanel();
      private JPanel jpanel3=new JPanel();
      private JPanel jpanel3_1=new JPanel();
      private JPanel jpanel3_2=new JPanel();
      public ReportDataCreat(){    /******************************************
        表模型的定义
        ******************************************/
        vect=new Vector();//实例化向量
        tm=new AbstractTableModel(){
            public int getColumnCount(){
            return title.length;}//取得表格列数
            public int getRowCount(){
            return vect.size();}//取得表格行数
            public Object getValueAt(int row,int column){
            if(!vect.isEmpty())
            return
           ((Vector)vect.elementAt(row)).elementAt(column);
            else
            return null;}//取得单元格中的属性值
            public String getColumnName(int column){
            return title[column];}//设置表格列名
            public void setValueAt(Object value,int row,int column){}
            //数据模型不可编辑,该方法设置为空
            public Class getColumnClass(int c){
            return getValueAt(0,c).getClass();
            }//取得列所属对象类
         };
         table=new JTable(tm);//生成自己的数据模型
         table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);//生成水平滚动条     jpanel1.setLayout(new FlowLayout());
         jpanel1.add(label1);
         jpanel1.add(text1);
         jpanel1.add(button1);     TitledBorder titledBorder1 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white,new Color(148, 145, 140)),"数据生成条件录入");
         //jpanel2.setLayout(new FlowLayout());
         jpanel2.setLayout(new BorderLayout());
         jpanel2.setBorder(titledBorder1);
         JScrollPane sp=new JScrollPane();
         sp.getViewport().add(table,null);
         //jpanel2.add(sp);
         jpanel2.add(sp,BorderLayout.CENTER);
         table.getColumnModel().getColumn(0).setPreferredWidth(200);
         table.getColumnModel().getColumn(1).setPreferredWidth(200);
         table.getTableHeader().setReorderingAllowed(false);     jpanel3_1.setLayout(new FlowLayout());
         jpanel3_1.add(label2);
         jpanel3_1.add(text2);
         jpanel3_1.add(button2);
         jpanel3_2.setLayout(new FlowLayout());
         jpanel3_2.add(button3);
         jpanel3_2.add(button4);
         jpanel3.setLayout(new GridLayout(2,1));
         jpanel3.add(jpanel3_1);
         jpanel3.add(jpanel3_2);   this.getContentPane().setLayout(new BorderLayout());
       this.getContentPane().add(jpanel1,"North");
       this.getContentPane().add(jpanel2,"Center");
       this.getContentPane().add(jpanel3,"South");
       //this.setResizable(false);
       this.setSize(500,300);
       this.setLocation(120,10);
       this.show();  }
     public static void main(String args[]){
        ReportDataCreat msb=new ReportDataCreat(); }}