Thank you, I have seem to found a solution to my problem, which is here:
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
public class groupWindow extends JFrame {
private String[] rightWords = new String[15];
private String[] leftWords = {"Some", "Random", "Crap", "hehe", "yeah", "nahh", "djkfgdjkhdjr", "bleed", "I hate you"};
// GUI
JList rightList = new JList();
JList leftList = new JList(leftWords);
JButton button = new JButton("MOVE >");
// Keep count of right list
int rightWordCount = 0;
public groupWindow() {
super("Making lists");
setLayout(new FlowLayout());
// create left list
leftList.setVisibleRowCount(4);
leftList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
// create right list
rightList.setVisibleRowCount(2);
rightList.setFixedCellWidth(75);
rightList.setFixedCellHeight(20);
rightList.setVisibleRowCount(4);
rightList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
// add everything to our window
add(new JScrollPane(leftList));
add(button);
add(new JScrollPane(rightList));
// listen for an action on the button
button.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent event) {
for (int i = rightWordCount; i < rightWordCount+leftList.getSelectedValuesList().toArray().length; i++) {
if (i==(rightWords.length)) {
System.out.print("Reached max limit for this array.\n");
break;
}
else
{
rightWords[i] = getStringIndex(leftList.getSelectedValuesList().toArray(), i-rightWordCount);
rightList.setListData(rightWords);
}
}
if (rightWordCount < rightWords.length)
rightWordCount = rightWordCount + leftList.getSelectedValuesList().toArray().length;
}
}
);
}
public String getStringIndex(Object[] word, int index) {
return word[index].toString();
}
}
I made a function (function==method, sorry not originally a Java programmer) which is "getStringIndex" which puts the array into it and also where I'd get to choose the array index at that point. I don't mind doing it this way as it seems reasonable but if there is a way to access the array indexes to functions like that individually, obviously that would be much better. Other then that, it works perfect and it doesn't delete my list now it just keeps adding on
well until it's reached its array length...Dynamic arrays? I don't think Java supports them, I was reading up something about collections/containers? ... Well better Study them up... Thanks for the help so far. Brilliant forums.
- Nicky