Add multiple data items inside JList
Hi all. I am currently developing a java application that will add
multiple data items into a JList. I have it adding data into a loop
using JList.setDataList. However it outputs everything correctly into
the loop but it will only add the last thing that the loop did into
the JList. Below is the code that I am using:
public void lstComputerNamesInitiate() {
remoteshutdown.mainScreen.lstComputerNames.setVisibleRowCount(-1);
int computerNumbers = 1;
String adminMachine = "RM49_AD";
String[] admin = { adminMachine };
System.out.println("Computer Name is: " + adminMachine);
remoteshutdown.mainScreen.lstComputerNames.setListData(admin);
while (computerNumbers != 31) {
if (computerNumbers < 10) {
String computerNames =
""+remoteshutdown.mainScreen.cboRoomNumber.getSelectedItem()+"" +
computerNumbers + "";
String getComputerNames[] = {computerNames};
remoteshutdown.mainScreen.lstComputerNames.setListData(
getComputerNames);
++computerNumbers;
System.out.println("Computer Name is: " +
computerNames);
} else {
String computerNames = "RM49_" + computerNumbers + "";
String[] getComputerNames = {computerNames};
remoteshutdown.mainScreen.lstComputerNames.setListData(
getComputerNames);
++computerNumbers;
System.out.println("Computer Name is: " +
computerNames);
}
}
}
This code is supposed to add each bit of data into a long list, for
example in the list box it might look something:
RM49_01
RM49_02
RM49_03
....
RM49_30
However it is only showing RM49_30.
Any help in this matter would be highly appreciated,
Thank you