Stoping repeated entries in JComboBox
Hi everyone,
I am coding a program in which JComboBox displays the name of every different computer which sends it connection request.But my program enters every name in JComboBox from which it accepts request despite it is already present in the box. Please help , I have tried everything I can do.
Thanks in advance
Code snippet :
Code:
String hostarray[] = new String[50];
public static int i=0;
public void addHost(String host)
{
check = true;
int j;
for( j=0; !hostarray[j].equals(null);j++)
{
if(hostarray[j].equals(host))
{
check =false;
break;}
}
if(check)
{
hostarray[i]=host;
UserInterface.jComboBox1.addItem(host);
UserInterface.jComboBox2.addItem(host);
UserInterface.jComboBox3.addItem(host);
UserInterface.jComboBox4.addItem(host);
UserInterface.jComboBox5.addItem(host);
UserInterface.jComboBox6.addItem(host);
}
i++;
System.out.println("Value of i "+i);
}