Guest User

Untitled

a guest
Jul 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. sList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
  2. sList.setVisibleRowCount(-1);
  3. sList.setLayoutOrientation(JList.HORIZONTAL_WRAP);
  4.  
  5. import java.awt.Dimension;
  6. import javax.swing.*;
  7.  
  8. public class Foo001 {
  9.  
  10. private static void createAndShowUI() {
  11. DefaultListModel model = new DefaultListModel();
  12. JList sList = new JList(model);
  13. for (int i = 0; i < 100; i++) {
  14. model.addElement("String " + i);
  15. }
  16.  
  17. sList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
  18. sList.setVisibleRowCount(-1);
  19. sList.setLayoutOrientation(JList.HORIZONTAL_WRAP);
  20.  
  21. JFrame frame = new JFrame("Foo001");
  22. frame.getContentPane().add(new JScrollPane(sList));
  23. frame.getContentPane().setPreferredSize(new Dimension(400, 300));
  24. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  25. frame.pack();
  26. frame.setLocationRelativeTo(null);
  27. frame.setVisible(true);
  28. }
  29.  
  30. public static void main(String[] args) {
  31. java.awt.EventQueue.invokeLater(new Runnable() {
  32. public void run() {
  33. createAndShowUI();
  34. }
  35. });
  36. }
  37. }
Add Comment
Please, Sign In to add comment