private void populateTable() { // Remove all rows first for (int i = tableModel.getRowCount() - 1; i >= 0; i--) { tableModel.removeRow(i); } for (Student student : students) { tableModel.addRow( new String[] { student.getFirstName(), student.getLastName(), student.getUsername(), student.getClassName() }); } }
public TeacherManagePasswords() { super(new BorderLayout()); setBackground(FWCConfigurator.bgColor); // Build title and north panel pnNorth = new JPanel(new FlowLayout(FlowLayout.CENTER)); pnNorth.setBackground(FWCConfigurator.bgColor); lblTitle = new TitleLabel("Reset Passwords", FWCConfigurator.RESET_PASSW_TITLE_IMG); pnNorth.add(lblTitle); // Build center panel pnCenter = new JPanel(new BorderLayout()); pnCenter.setBackground(FWCConfigurator.bgColor); // Build table of students tableModel = new DisabledTableModel(); tableModel.setColumnIdentifiers( new String[] {"First Name", " Last " + "Name", "Username", "Class"}); studentsTable = new JTable(tableModel); studentsTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); studentsTable.setFillsViewportHeight(true); studentsTable.getTableHeader().setFont(new Font("Calibri", Font.PLAIN, 18)); studentsTable.setFont(new Font("Calibri", Font.PLAIN, 18)); studentsTable.setRowHeight(studentsTable.getRowHeight() + 12); // Populate the table only with students that need a password reset students = FWCConfigurator.getTeacher().getStudentsRequestedReset(); populateTable(); tableScroll = new JScrollPane( studentsTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); tableScroll.setBackground(FWCConfigurator.bgColor); tableScroll.setBorder( BorderFactory.createCompoundBorder( new EmptyBorder(10, 100, 10, 100), new LineBorder(Color.black, 1))); pnCenter.add(tableScroll, BorderLayout.CENTER); // Build south panel pnButtons = new JPanel(new FlowLayout(FlowLayout.CENTER)); pnButtons.setBackground(FWCConfigurator.bgColor); pnButtons.setBorder(BorderFactory.createEmptyBorder(0, 100, 20, 100)); btnReset = new ImageButton("Reset Selected", FWCConfigurator.RESET_SELECTED_IMG, 150, 50); btnReset.addActionListener(new ResetListener()); btnResetAll = new ImageButton("Reset All", FWCConfigurator.RESET_ALL_IMG, 150, 50); btnResetAll.addActionListener(new ResetListener()); pnButtons.add(btnReset); pnButtons.add(btnResetAll); this.add(pnNorth, BorderLayout.NORTH); this.add(pnCenter, BorderLayout.CENTER); this.add(pnButtons, BorderLayout.SOUTH); }