日期:2014-05-20  浏览次数:20612 次

为什么我的JTable没有显示出来
DefaultTableModel dtm;
JTable table;
ListSelectionModel selectionMode ;
String preBook[] = {"抵店时间","预住时长","单位"};
   



  dtm = new DefaultTableModel();
table = new JTable(dtm);
table.setPreferredScrollableViewportSize(new Dimension(220,180));
table.setShowHorizontalLines(true);
table.setShowVerticalLines(true);
table.setCellSelectionEnabled(true);//设定可以选定单个的元素
selectionMode=table.getSelectionModel();
selectionMode.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
// selectionMode.addListSelectionListener(new MyTableSelectionListener());
dtm.setColumnIdentifiers(preBook);
String[] result ={"1","2","3"} ;
dtm.addRow(result);
   

  JScrollPane isp = new JScrollPane(table);


可是jsp这个面板没有显示啊怎么办,求帮助!

------解决方案--------------------
DefaultTableModel dtm;
JTable table;
ListSelectionModel selectionMode ;
String preBook[] = {"抵店时间","预住时长","单位"};




dtm = new DefaultTableModel();
table = new JTable(dtm);
final JScrollPane isp = new JScrollPane(table);
getContentPane().add(isp, BorderLayout.CENTER);
isp.setViewportView(table);
table.setPreferredScrollableViewportSize(new Dimension(220,180));
table.setShowHorizontalLines(true);
table.setShowVerticalLines(true);
table.setCellSelectionEnabled(true);//设定可以选定单个的元素
selectionMode=table.getSelectionModel();
selectionMode.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
// selectionMode.addListSelectionListener(new MyTableSelectionListener());
dtm.setColumnIdentifiers(preBook);
String[] result ={"1","2","3"} ;
dtm.addRow(result);

好了 你试试
------解决方案--------------------
Java code

DefaultTableModel dtm;
JTable table;
ListSelectionModel selectionMode ;
String preBook[] = {"抵店时间","预住时长","单位"};
    



  dtm = new DefaultTableModel();
table = new JTable(dtm);
table.setPreferredScrollableViewportSize(new Dimension(220,180));
table.setShowHorizontalLines(true);
table.setShowVerticalLines(true);
table.setCellSelectionEnabled(true);//设定可以选定单个的元素
selectionMode=table.getSelectionModel(); 
selectionMode.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 
// selectionMode.addListSelectionListener(new MyTableSelectionListener());
dtm.setColumnIdentifiers(preBook);
String[] result ={"1","2","3"} ;
dtm.addRow(result);
    

JScrollPane isp = new JScrollPane(table);
isp.setBounds(new Rectangle(20, 20, 200, 200));//最好设置一下大小
this.getContentPane().add(isp);