Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

More JForm trouble

Featured Replies

4a78cee743c6f174a0bbc4cf5ad24027.png

 

 

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:

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.

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?
  • 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?

  • 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....

Always good to see a helpful Scripter III rank....

Myyyysterryy is fun at parties

  • Author

Proper list code

163595f83c.png

 

 

Properly using it

ea0da19e4b.png

 

 

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 by Paradox68

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.

 

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 by Explv

  • 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

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.