[英]how to make this jtable scrollable
當我嘗試在表格中放置垂直滾動窗格時,表格ctab消失了。 這是代碼:
ctab = new JTable();
ctab.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
ctab.setBounds(15, 97, 780, 347);
frmKusinaNiKambal.getContentPane().add(ctab);
ctab.setModel(new DefaultTableModel(
new Object[][] {
{"", "", null, null, null, null, null, null, null},
},
new String[] {
"Contract #", "Engager", "Contact #", "Client Address", "Date", "Time", "Event Address", "Contract FilePath", "Referred By"
}
) {
boolean[] columnEditables = new boolean[] {
false, false, false, false, false, false, false, false, false
};
public boolean isCellEditable(int row, int column) {
return columnEditables[column];
}
});
ctab.getColumnModel().getColumn(3).setPreferredWidth(102);
ctab.getColumnModel().getColumn(4).setPreferredWidth(62);
ctab.getColumnModel().getColumn(5).setPreferredWidth(41);
ctab.getColumnModel().getColumn(6).setPreferredWidth(95);
ctab.isEnabled();
我怎樣才能使該表可滾動?
我沒有在您發布的代碼中看到您在任何地方處理JScrollPane的問題。 相反,您的代碼顯示將JTable直接放置到contentPane中。
解決方案是
setViewportView(...)
並傳入JTable來實現。 有用的教程鏈接:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.