简体   繁体   中英

adding a value to combo box from output of another application using java

I have a java application that has a combo box it displays the available com ports.

I have another application that displays the Bluetooth names.

Now i would like to display the Bluetooth names along with the com ports number in my original application how can i do it ?

I used the following code to display the com ports in combobox

      public Vector LoadComPorts()
        {
                   int totalElements;
                    CommPortIdentifier portId;
                    Enumeration en = CommPortIdentifier.getPortIdentifiers();
                    Vector listData = new Vector(8);
                    // Walk through the list of port identifiers and, if it
                           // is a serial port, add its name to the list.
                    while (en.hasMoreElements())
                    {
                                portId = (CommPortIdentifier) en.nextElement();
                                if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL)
                                {
                                            listData.addElement(portId.getName());
                                }

                                           //
                                            //  listData.addElement("COM30"); //ADDEDLINE
                    }

                   //   listData.addElement("COM29"); //ADDEDLINE

                    totalElements = listData.size();

                    //Iterate through the vector
                    for (int index = 0; index < totalElements; index ++)
                    {
                                System.out.println(listData.get(index));
                    }

                    return listData;
        }

     public Vector LoadComPorts2() //addedline
        {
               Vector listData = new Vector(8);

                String[] portNames = SerialPortList.getPortNames();

                for (String port : portNames)
                {
                   listData.add(port);
                }


               return listData;
}

If you have source of the other application then call the method which enumerate the bluetooth ports. If you don't have source and have only executable then you need to give more information. With whatever info supplied by you it is not possible to give an acceptable answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM