adding values in jcombobox dynamically from database

I have 3 radio buttons. If button 1 is selected then i want to show only 2 values from the database, if I select other 2, then I want to show 5 values. I will do this by generating a event method for the radio button. The problem is to select values from the database and add it to the combobox. I am using xampp for the database. Thank you

Answers


To modify UI components use UIThreads EventQueue.invokeLater or SwingUtilities.invokeLater. Look this sample code:

SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            try {
                Socket socket = new Socket("127.0.0.1", 6677);

                ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
                ObjectInputStream in = new ObjectInputStream(socket.getInputStream());

                out.writeObject(some_data_for_send_to_server_socket);
                out.flush();

                ArrayList<String> data =(ArrayList<String>)in.readObject();
                if (!data.isEmpty()){
                    for(String s:data){
                        yourComboBox.addItem(s);
                    }
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

Need Your Help

Increment value in mysql update query

php mysql sql sql-update

I have made this code for giving out +1 point, but it doesn't work properly.

MVC files organization in folders

c# asp.net-mvc

I'm building a web application using ASP.NET MVC and i have a question about the files organization.