Guest User

Untitled

a guest
Oct 17th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5.  
  6. package Java64;
  7. import javax.swing.*;
  8. import javax.swing.event.*;
  9. import java.awt.*;
  10. /**
  11. *
  12. * @author ggj11091
  13. */
  14. public class JavaList extends JFrame{
  15. private JList list;
  16. private static String[] colornames = {"black","blue", "red", "white"};
  17. private static Color[] colors = {Color.BLACK,Color.BLUE,Color.RED,Color.WHITE};
  18. public JavaList(){
  19. super("Java List");
  20. setLayout(new FlowLayout());
  21. list = new JList(colornames);
  22. list.setVisibleRowCount(4);
  23. list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  24. add(new JScrollPane(list));
  25. list.addListSelectionListener(new ListSelectionListener(){
  26. public void valueChanged(ListSelectionEvent event){
  27. getContentPane().setBackground(colors[list.getSelectedIndex()]);
  28. }
  29. }
  30. );
  31.  
  32. }
  33. }
Add Comment
Please, Sign In to add comment