JTable table = new JTable(); table.setSelectionBackground(Color.YELLOW);
JTable table = new JTable(); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setSelectionBackground(Color.RED);This code sets the selection mode to single selection and changes the selection background to red. In both examples, the package library used is javax.swing.