0 Members and 1 Guest are viewing this topic.
DefaultListModel kubesN = new DefaultListModel();
final String kubes[] = { "Bedrock", "Water", "Dirt", "Grassy Dirt", "Rock", "Wood", "Green Leaves", "Old Citronox", "Short Grass", "Tall Grass", "Wood Rose", "Mushlite", "Stellar Sand", "Creeping Vines", "Hanging Grass", "Cactus", "Citronox", "ESCorp Box", "Cracked Rock", "HardRoq", "Pyrite", "Cactus Root", "Cactus Flower", "Blue Mineral", "Blue Crystal", "Copper", "Hangar Ceiling Lighting", "Copper Arrow", "Bound Copper", "Copper Wire Mesh", "Hangar Lighting", "Purple Leaves", "Pink Leaves", "Moon Earth", "Grassy Moon Earth", "Moon Rock", "Moon Dust", "Lumen Rock", "Dead Lumen Rock", "Lumen Rock Column", "Moon Water", "Moon Rock Column", "Cracked Moon Rock", "Purple Stain", "Pink Stain" }; java.util.Arrays.sort(kubes); JList kube = new JList(kubes); kube.setModel(kubesN); ListListener listlistener = new ListListener(); kube.addListSelectionListener(listlistener); for (int i = 0; i < kubes.length; i++) kubesN.addElement(kubes[i]); kube.setVisibleRowCount(5); kube.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane kubeView = new JScrollPane(kube);
private static class ListListener implements ListSelectionListener{ public void valueChanged(ListSelectionEvent e){ if (!e.getValueIsAdjusting()){ int index = kube.getSelectedIndex(); System.out.println(index); } } }}
JList kube = new JList(kubes);
kube.getSelectedIndex();