I have a table with 5 columns and my last column is the working days of a teacher.
the user select the days the teacher work with a checkbox, and the row is added to the Jtable when the user press the add button.
I am limited in my width and want to use Jscrollpane's horizontal scroll bar to display the data full
for some reason, when adding new rows and exceeding the size i allocated for the JTable the vertial scroll bar does appear, but its not the case for the horizontal scroll bar.
I am adding a picture:
as you can see I have a vertical scroll bar, but at line 15 the days are cut off, i would like it to have an horizontal scroll bar so i could see the full data
scrollPane = new JScrollPane();
scrollPane.setBorder(new EmptyBorder(0, 0, 0, 0));
scrollPane.setOpaque(false);
scrollPane.setBounds(10, 11, 508, 241);
teacherPanel.add(scrollPane);
String[] columnNames = { "ID", "Name", "Course", "Max Hours", "Days" };
teacherTableModel = new DefaultTableModel();
teacherTableModel.setColumnIdentifiers(columnNames);
teacherTable = new JTable(teacherTableModel) {
public boolean isCellEditable(int data, int columns) {
return false;
}
};
teacherTable.setFillsViewportHeight(true);
teacherTable.setOpaque(false);
teacherTable.setGridColor(new Color(0, 0, 0));
teacherTable.setFont(new Font("Tahoma", Font.BOLD, 12));
teacherTable.setBackground(new Color(204, 204, 204));
teacherTable.setFocusable(false);
teacherTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
teacherTable.getTableHeader().setResizingAllowed(false);
teacherTable.getTableHeader().setReorderingAllowed(false);
teacherTable.getTableHeader().setOpaque(false);
teacherTable.getTableHeader().setFont(new Font("Tahoma", Font.BOLD, 12));
teacherTable.getTableHeader().setBackground(new Color(71, 71, 71));
teacherTable.getTableHeader().setForeground(new Color(204, 204, 204));
DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
centerRenderer.setHorizontalAlignment(SwingConstants.CENTER);
for (int i = 0; i < 5; i++) {
teacherTable.getColumnModel().getColumn(i).setCellRenderer(centerRenderer);
}
teacherTable.getColumnModel().getColumn(0).setMaxWidth(25);
teacherTable.getColumnModel().getColumn(1).setMinWidth(150);
teacherTable.getColumnModel().getColumn(3).setMaxWidth(75);
teacherTable.getColumnModel().getColumn(4).setMinWidth(200);
scrollPane.setViewportView(teacherTable);
scrollPane.getViewport().setBackground(new Color(62, 62, 62));
teacherTableRow = new Object[5];