Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.vidux.gui.rwt;
- import java.util.Comparator;
- import org.eclipse.swt.SWT;
- import org.eclipse.swt.layout.GridLayout;
- import org.eclipse.swt.widgets.Combo;
- import org.eclipse.swt.widgets.Display;
- import org.eclipse.swt.widgets.Shell;
- public class ComboTest {
- public static final Comparator<String> comparator = (string1, string2) -> string2.compareTo(string1);
- public static void main(String[] a) {
- Display display = new Display();
- Shell shell = new Shell(display);
- shell.setLayout(new GridLayout());
- //Combo combo = new ViduxComboAddFix(shell, SWT.READ_ONLY | SWT.BORDER);
- Combo combo = new Combo(shell, SWT.READ_ONLY | SWT.BORDER);
- addItem("Central 1 (40/40)", combo);
- addItem("Central 2 (40/40)", combo);
- addItem("Central 10 (40/40)", combo);
- addItem("Central 3 (40/40)", combo);
- addItem("Central 11 (40/40)", combo);
- addItem("Central 4 (40/40)", combo);
- addItem("Central 12 (40/40)", combo);
- combo.redraw();
- shell.open();
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch()) {
- display.sleep();
- }
- }
- }
- private static void addItem(String newItem, Combo combo) {
- System.out.println("ADD: " + newItem);
- boolean add = false;
- for (String text : combo.getItems()) {
- int index = combo.indexOf(text);
- if (comparator.compare(newItem, text) < 0) {
- // String[] oldItems = combo.getItems();
- // List<String> newItemList = new ArrayList<>();
- // for (int i = 0; i < index; i++) {
- // newItemList.add(oldItems[i]);
- // }
- // newItemList.add(newItem);
- // for (int i = index; i < oldItems.length; i++) {
- // newItemList.add(oldItems[i]);
- // }
- //combo.removeAll();
- //combo.setItems(newItemList.toArray(new String[0]));
- combo.add(newItem, index);
- add = true;
- break;
- }
- }
- if (!add)
- combo.add(newItem);
- System.out.println("after");
- for (String text : combo.getItems()) {
- System.out.println(text);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement