首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

为什么小弟我的JTable没有显示出来

2012-01-22 
为什么我的JTable没有显示出来DefaultTableModel dtmJTable tableListSelectionModel selectionMode St

为什么我的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); 

热点排行