Paradox68 Posted January 3, 2016 Share Posted January 3, 2016 Trying to create a method to send list items back and forth using their respective buttons. //---- button1 ---- button1.setText("> Foes >"); button1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (!list1.isSelectionEmpty()) { list2.add(list1.getSelectedValue(), list1.getComponent(list1.getSelectedIndex())); list1.remove(list1.getComponent(list1.getSelectedIndex())); } } }); Tried this method. I know i'm doing something wrong because I have no idea what a component is and I couldn't find a method that didn't use components with Intellisense. Someone helppppp D: Quote Link to comment Share on other sites More sharing options...
Token Posted January 3, 2016 Share Posted January 3, 2016 If you use a GUI creation tool make sure you change all list models to DefaultListModel because most of them generate AbstractListModel which cannot be used properly. Also adding items to a JList is done via adding the respective item to its list model. Quote Link to comment Share on other sites More sharing options...
AresScripts Posted January 3, 2016 Share Posted January 3, 2016 If you use a GUI creation tool make sure you change all list models to DefaultListModel because most of them generate AbstractListModel which cannot be used properly. Also adding items to a JList is done via adding the respective item to its list model.freestyle? Quote Link to comment Share on other sites More sharing options...
Paradox68 Posted January 3, 2016 Author Share Posted January 3, 2016 //---- list1 ---- list1.setModel(new DefaultListModel<String>() { /** * */ private static final long serialVersionUID = 5147152121755459135L; String[] values = { main.monstersNearby[0], main.monstersNearby[1], main.monstersNearby[2], main.monstersNearby[3], main.monstersNearby[4], main.monstersNearby[5], main.monstersNearby[6], main.monstersNearby[7], main.monstersNearby[8], main.monstersNearby[9], main.monstersNearby[10], main.monstersNearby[11], main.monstersNearby[12], main.monstersNearby[13], main.monstersNearby[14], main.monstersNearby[15], main.monstersNearby[16], main.monstersNearby[17], main.monstersNearby[18], main.monstersNearby[19], }; @Override public int getSize() { return values.length; } @Override public String getElementAt(int i) { return values[i]; } }); scrollPane1.setViewportView(list1); } //---- button1 ---- button1.setText("> Foes >"); button1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (!list1.isSelectionEmpty()) { list2.setModel list1.remove(list1.getComponent(list1.getSelectedIndex())); } } }); If you use a GUI creation tool make sure you change all list models to DefaultListModel because most of them generate AbstractListModel which cannot be used properly. Also adding items to a JList is done via adding the respective item to its list model. What do you think would be a good method to handle this? Quote Link to comment Share on other sites More sharing options...
Novak Posted January 3, 2016 Share Posted January 3, 2016 problem #1 is that you are using a gui tool 2 Quote Link to comment Share on other sites More sharing options...
Token Posted January 3, 2016 Share Posted January 3, 2016 freestyle? If you don't use a GUI creation tool you are wasting your life. 1 Quote Link to comment Share on other sites More sharing options...
Mysteryy Posted January 3, 2016 Share Posted January 3, 2016 insert a into b and then press the 1 key 12 times and spin in a circle twice. ???? Quote Link to comment Share on other sites More sharing options...
Token Posted January 3, 2016 Share Posted January 3, 2016 Proper list code Properly using it Quote Link to comment Share on other sites More sharing options...
Paradox68 Posted January 3, 2016 Author Share Posted January 3, 2016 insert a into b and then press the 1 key 12 times and spin in a circle twice. ???? Always good to see a helpful Scripter III rank.... 1 Quote Link to comment Share on other sites More sharing options...
AresScripts Posted January 3, 2016 Share Posted January 3, 2016 If you don't use a GUI creation tool you are wasting your life.no I mean your profile picture. Thats freestyle wrestling. 1 Quote Link to comment Share on other sites More sharing options...
Chris Posted January 3, 2016 Share Posted January 3, 2016 Always good to see a helpful Scripter III rank.... Myyyysterryy is fun at parties Quote Link to comment Share on other sites More sharing options...
Paradox68 Posted January 3, 2016 Author Share Posted January 3, 2016 (edited) Proper list code Properly using it In your snippet, what is core.removeComplexTask(list.getSelectedIndex()); Also why isn't it letting me reference addValues()? Sorry for the needing spoonfeeding I just came back from a long break trying to figure it all out again and I hate GUIs. I still can't seem to get it to add a value to the list. Edited January 3, 2016 by Paradox68 Quote Link to comment Share on other sites More sharing options...
Token Posted January 3, 2016 Share Posted January 3, 2016 In your snippet, what is core.removeComplexTask(list.getSelectedIndex()); Also why isn't it letting me reference addValues()? Sorry for the needing spoonfeeding I just came back from a long break trying to figure it all out again and I hate GUIs. I still can't seem to get it to add a value to the list. You dont need to change anything to the addValues() method. Use it as I wrote it. Put all values in the String[] above that. Ignore core related code because that snippet is just an implementation of JFrame in my scripts and the core stuff is not related to OSBot API. Was meant to show how the listmodel.add and listmodel.remove methods work. Quote Link to comment Share on other sites More sharing options...
Explv Posted January 3, 2016 Share Posted January 3, 2016 (edited) Tried this method. I know i'm doing something wrong because I have no idea what a component is and I couldn't find a method that didn't use components with Intellisense. Someone helppppp D: I recommend that you learn how to do these basic Swing tasks without a GUI builder, before using a GUI builder Just create two JList<String> intialised with DefaultListModel<String> and then use model.addElement and model.remove: String[] friends = { "Noob1", "Noob2", "Noob3", "Noob4" }; DefaultListModel<String> friendsModel = new DefaultListModel<>(); for(String friend : friends){ friendsModel.addElement(friend); } JList<String> friendsList = new JList<>(friendsModel); DefaultListModel<String> foesModel = new DefaultListModel<>(); JList<String> foesList = new JList<>(foesModel); JButton addFoe = new JButton("> Foes >"); addFoe.addActionListener(e -> { for(int i : friendsList.getSelectedIndices()) foesModel.addElement(friendsModel.remove(i)); }); JButton addFriend = new JButton("< Friends <"); addFriend.addActionListener(e -> { for(int i : foesList.getSelectedIndices()) friendsModel.addElement(foesModel.remove(i)); }); Edited January 3, 2016 by Explv 1 Quote Link to comment Share on other sites More sharing options...
Paradox68 Posted January 3, 2016 Author Share Posted January 3, 2016 I recommend that you learn how to do these basic Swing tasks without a GUI builder, before using a GUI builder Just create two JList<String> intialised with DefaultListModel<String> and then use model.addElement and model.remove: String[] friends = { "Noob1", "Noob2", "Noob3", "Noob4" }; DefaultListModel<String> friendsModel = new DefaultListModel<>(); for(String friend : friends){ friendsModel.addElement(friend); } JList<String> friendsList = new JList<>(friendsModel); DefaultListModel<String> foesModel = new DefaultListModel<>(); JList<String> foesList = new JList<>(foesModel); JButton addFoe = new JButton("> Foes >"); addFoe.addActionListener(e -> { for(int i : friendsList.getSelectedIndices()) foesModel.addElement(friendsModel.remove(i)); }); JButton addFriend = new JButton("< Friends <"); addFriend.addActionListener(e -> { for(int i : foesList.getSelectedIndices()) friendsModel.addElement(foesModel.remove(i)); }); Thank you. I've solved the list building issues but you wouldn't happen to know why my script closes itself instantly after starting? Would you be able to help me for a minute on it because I can't find any explanation. SOMETIMES the script will run and the GUI will build, majority of the time it instantly exits script and says Error at onStart(). I only have the GUI opening method in onStart so I know it's the UI class but I can't imagine why.. 0 errors and 0 warnings. Quote Link to comment Share on other sites More sharing options...