SRL Archive - Java Help and Tutorials

Is it possible?[Java]


JPHamlett

2011-07-27 10:51:06

Is it possible to have a JList, update in a JScrollPanel during Runtime?

I want to be able to add a string to the JList during runtime, and then have it be displayed in a JScrollPane during runtime.

An example would be RSBot's debug console at the bottom of their GUI.

I don't know how they do it though.

My ultimate goal is to create that kind of GUI, not a RS Client just the debug part.


Thanks, JP


PS I have been messing around with it and I just cannot make it work.

I can't attach source code as I'm not at my house.

Brandon

2011-07-27 11:41:29

I believe below is what your looking for.. U can add to a list/combobox at anytime during runtime..

Im not a java user so I wouldn't know. I can read it but not write it.. if u can translate c++ to java then I'd write the code for u.. The code below is from the sun java website and it seems to do what u ask..



//The action that will be performed.. Maybe a button press.. I would personally change this event to Control.Changed or something instead of waiting on a button press to do it..
public void actionPerformed(ActionEvent e) {

String name = employeeName.getText(); //Grab the text from user

//User did not type in a unique name...
if (name.equals("") || alreadyInList(name)) {
Toolkit.getDefaultToolkit().beep();
employeeName.requestFocusInWindow();
employeeName.selectAll();
return;
}

int index = list.getSelectedIndex(); //get selected index
if (index == -1) { //no selection, so insert at beginning
index = 0;
}
else {
//add after the selected item
index++;
}

//I would personally change this to append to the list..
//By doing (Index count - 1) then insert element to that.

[B]listModel.insertElementAt(employeeName.getText(), index);[/B]
//Reset the text field.
employeeName.requestFocusInWindow();
employeeName.setText(""); //Select the new item and make it visible.
list.setSelectedIndex(index);
list.ensureIndexIsVisible(index);
}

regex_

2011-08-03 06:36:15

use a DefaultListModel. Attach it to the JList then use listModelInstance.addElement("YOUR_STRING");