January 3, 201610 yr 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:
January 3, 201610 yr 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.
January 3, 201610 yr 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?
January 3, 201610 yr Author //---- 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?
January 3, 201610 yr insert a into b and then press the 1 key 12 times and spin in a circle twice. ????
January 3, 201610 yr Author 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....
January 3, 201610 yr If you don't use a GUI creation tool you are wasting your life.no I mean your profile picture. Thats freestyle wrestling.
January 3, 201610 yr Always good to see a helpful Scripter III rank.... Myyyysterryy is fun at parties
January 3, 201610 yr Author 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, 201610 yr by Paradox68
January 3, 201610 yr 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.
January 3, 201610 yr 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, 201610 yr by Explv
January 3, 201610 yr Author 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.
Create an account or sign in to comment