Advertisement
Guest User

Untitled

a guest
May 16th, 2018
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. package net.vidux.gui.rwt;
  2.  
  3. import java.util.Comparator;
  4.  
  5. import org.eclipse.swt.SWT;
  6. import org.eclipse.swt.layout.GridLayout;
  7. import org.eclipse.swt.widgets.Combo;
  8. import org.eclipse.swt.widgets.Display;
  9. import org.eclipse.swt.widgets.Shell;
  10.  
  11. public class ComboTest {
  12.  
  13. public static final Comparator<String> comparator = (string1, string2) -> string2.compareTo(string1);
  14.  
  15. public static void main(String[] a) {
  16. Display display = new Display();
  17. Shell shell = new Shell(display);
  18. shell.setLayout(new GridLayout());
  19.  
  20. //Combo combo = new ViduxComboAddFix(shell, SWT.READ_ONLY | SWT.BORDER);
  21. Combo combo = new Combo(shell, SWT.READ_ONLY | SWT.BORDER);
  22.  
  23. addItem("Central 1 (40/40)", combo);
  24. addItem("Central 2 (40/40)", combo);
  25. addItem("Central 10 (40/40)", combo);
  26. addItem("Central 3 (40/40)", combo);
  27. addItem("Central 11 (40/40)", combo);
  28. addItem("Central 4 (40/40)", combo);
  29. addItem("Central 12 (40/40)", combo);
  30.  
  31. combo.redraw();
  32.  
  33. shell.open();
  34. while (!shell.isDisposed()) {
  35. if (!display.readAndDispatch()) {
  36. display.sleep();
  37. }
  38. }
  39. }
  40.  
  41. private static void addItem(String newItem, Combo combo) {
  42. System.out.println("ADD: " + newItem);
  43. boolean add = false;
  44. for (String text : combo.getItems()) {
  45. int index = combo.indexOf(text);
  46. if (comparator.compare(newItem, text) < 0) {
  47. // String[] oldItems = combo.getItems();
  48. // List<String> newItemList = new ArrayList<>();
  49. // for (int i = 0; i < index; i++) {
  50. // newItemList.add(oldItems[i]);
  51. // }
  52. // newItemList.add(newItem);
  53. // for (int i = index; i < oldItems.length; i++) {
  54. // newItemList.add(oldItems[i]);
  55. // }
  56. //combo.removeAll();
  57. //combo.setItems(newItemList.toArray(new String[0]));
  58. combo.add(newItem, index);
  59. add = true;
  60. break;
  61. }
  62. }
  63. if (!add)
  64. combo.add(newItem);
  65. System.out.println("after");
  66. for (String text : combo.getItems()) {
  67. System.out.println(text);
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement