When I try to put a vertical scrollpane in the table, the table ctab just disappears. here is the code:
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();
How can i get this table to be scrollable?
I don't see in your posted code where you deal anywhere with a JScrollPane. Rather your code shows you placing the JTable directly into the contentPane.
The solution is to
setViewportView(...)
on the JScrollPane and passing in the JTable. Useful Tutorial Links:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.