search from database with combo box

hi how can I search value from database using combobox for example I enter username and return the detail of that username

this is my code
      
public CreateUserGUI()
	{
		
	//	backPanel = new JPanel(new GridBagLayout());
	//	topPanel = new JPanel(new GridBagLayout());
		JTabbedPane jtp = new JTabbedPane();
		 getContentPane().add(jtp);
		
		
		
    	JPanel jp1 = new JPanel();
        JPanel jp2 = new JPanel();
        JPanel jp3 = new JPanel();
        JPanel jp4 = new JPanel();
		
		nameLabel = new JLabel("Name : ");
	    txtName = new JTextField(15);
		txtName.setMinimumSize(txtName.getPreferredSize());
		
		
		 JLabel label1 = new JLabel();
        label1.setText("You are in area of creating new User");
        JLabel label2 = new JLabel();
        label2.setText("You are in area of Updating user Information");
        JLabel label3 = new JLabel();
        label3.setText("You are in area of seting  user Inactive");
        JLabel label4 = new JLabel();
        label4.setText("You are in area to Search user Information");
        
        
        
         
			
	    	surnameLabel = new JLabel("Surname : ");
	    	txtSurname = new JTextField(15);
	    	txtSurname.setMinimumSize(	txtSurname.getPreferredSize());
	    	
	    	
	    	usernameLabel = new JLabel("Username : ");
	    	txtUsername = new JTextField(15);
	    	txtUsername.setMinimumSize(	txtUsername.getPreferredSize());
	    	
	    	passwordLabel = new JLabel("Password : ");
	    	passwordField = new  JPasswordField(15);
	    	passwordField.setMinimumSize(passwordField.getPreferredSize());
	    			
			
			
		
		
		txtName = new JTextField();
		txtSurname = new JTextField();
		txtUsername = new JTextField();
		passwordField = new JPasswordField();
		
		
		nameLabel = new JLabel("Name : ");
		surnameLabel = new JLabel("Surname : ");
		usernameLabel = new JLabel("Username : ");
		passwordLabel = new JLabel("Password : ");
		//****statusComboLabel = new JLabel("Status : ");
		
		
    //	topPanel.setLayout(null);
		nameLabel.setBounds(1, 30, 150, 20);
	   	txtName.setBounds(70,30,150,20);
		surnameLabel.setBounds(1, 65, 150, 20);
		txtSurname.setBounds(70,65,150,20);
		passwordLabel.setBounds(110, 100, 80, 20);
		passwordField.setBounds(150, 160, 50, 20);  
		
		
      /*topPanel.add(nameLabel);
      topPanel.add(txtName);
      topPanel.add(surnameLabel);
      topPanel.add(txtSurname);
      topPanel.add(passwordLabel);
      topPanel.add(passwordField);*/
      
        jp1.add(label1);
        jp1.add(nameLabel);
        jp1.add(txtName);
        jp1.add(txtSurname);
        jp1.add(passwordLabel);
        jp1.add(passwordField);
        jp2.add(label2);
        jp3.add(label3);
        jp4.add(label4);
        jtp.addTab("create", jp1);
       // jtp.add(topPanel);
        jtp.addTab("update", jp2);
        jtp.addTab("Delete", jp3);
        jtp.addTab("Search", jp4);
		
	
		
	this.setTitle("Create User");
    this.setSize(600,450);
		
		
	Toolkit toolkit = getToolkit();
		
		Dimension size = toolkit.getScreenSize();
		
		setLocation(size.width/2 - getWidth()/2,
				size.height/2 - getHeight()/2);		
		
		
		
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//this.getContentPane().add(topPanel);
		
this.setVisible(true);
		

		
	}

Open in new window

     

I what a search in 4th tab somethis like this
import javax.swing.*;
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;//where do I get this am getting error is not recognise
import java.awt.*;

public class Demo {

    JFrame frame = new JFrame("");
    AutoCompleteDecorator decorator;
    JComboBox combobox;

    public Demo() {
        combobox = new JComboBox(new Object[]{"","Ester", "Jordi",
            "Jordina", "Jorge", "Sergi"});//I what to searc from database
        AutoCompleteDecorator.decorate(combobox);
        frame.setSize(400,400);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLayout(new FlowLayout());

        frame.add(combobox);
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        Demo d = new Demo();
    }
}

Open in new window

chalie001Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gurpsbassiCommented:
This is quite an open ended question which is going to lead to many more questions from experts.

How do you intend to talk to the database? what database do you have? Are you using a ORM or plain JDBC?
0
chalie001Author Commented:
am using mongo db this is how am connection to db


import com.mongodb.DB;
import com.mongodb.Mongo;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;



public class ConnectToDB {
	
	private DB db = null;
	private Mongo mongoClient = null;
	private Properties properties = new Properties();;
        private InputStream input = null;
        
	public ConnectToDB() {
	
		getDB();
		
	}
	
	
	private boolean connectToDB() throws Exception{
		input = new FileInputStream("dsnApp.properties");
                properties.load(input);
                
		  this.mongoClient = new Mongo(properties.getProperty("mongoDBipAddress"), Integer.valueOf(properties.getProperty("mongoDBport")));
                  
		  this.db = mongoClient.getDB("dsn");
		  		  
		  if(db != null)
		  {
			  return true;
		  }
		     
		 return false;
	}
	
	
	public DB getDB() {
		
		try {
			if(connectToDB())
			{
				return db;
			}
			else
			{
				connectToDB();
				return db;
			}
		} catch (Exception e) {
			
			System.out.println("Something went wrong while trying to connect to the database..");
			e.printStackTrace();
			return null;
		}
	}
  
}

Open in new window


I what something like this but using combobox and using mongo bd
import javax.swing.*;

import java.awt.event.*;

import java.awt.*;

import java.sql.*;

 

public class SwingSearchApp extends JFrame implements ActionListener {

 

//Initializing Components

    JLabel lb, lb1, lb2, lb3, lb4, lb5;

    JTextField tf1, tf2, tf3, tf4, tf5;

    JButton btn;

 

    //Creating Constructor for initializing JFrame components

    SwingSearchApp() {

        //Providing Title

        super("Fetching Student Information");

        lb5 = new JLabel("Enter Name:");

        lb5.setBounds(20, 20, 100, 20);

        tf5 = new JTextField(20);

        tf5.setBounds(130, 20, 200, 20);

 

        btn = new JButton("Submit");

        btn.setBounds(50, 50, 100, 20);

        btn.addActionListener(this);

 

        lb = new JLabel("Fetching Student Information From Database");

        lb.setBounds(30, 80, 450, 30);

        lb.setForeground(Color.red);

        lb.setFont(new Font("Serif", Font.BOLD, 20));

        setVisible(true);

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        setSize(500, 500);

 

        lb1 = new JLabel("U_Name:");

        lb1.setBounds(20, 120, 100, 20);

        tf1 = new JTextField(50);

        tf1.setBounds(130, 120, 200, 20);

        lb2 = new JLabel("U_Mail:");

        lb2.setBounds(20, 150, 100, 20);

        tf2 = new JTextField(100);

        tf2.setBounds(130, 150, 200, 20);

        lb3 = new JLabel("U_Pass:");

        lb3.setBounds(20, 180, 100, 20);

        tf3 = new JTextField(50);

        tf3.setBounds(130, 180, 200, 20);

        lb4 = new JLabel("U_Country:");

        lb4.setBounds(20, 210, 100, 20);

        tf4 = new JTextField(50);

        tf4.setBounds(130, 210, 100, 20);

        setLayout(null);

 

        //Add components to the JFrame

        add(lb5);

        add(tf5);

        add(btn);

 

        add(lb);

        add(lb1);

        add(tf1);

        add(lb2);

        add(tf2);

        add(lb3);

        add(tf3);

        add(lb4);

        add(tf4);

 

        //Set TextField Editable False

        tf1.setEditable(false);

        tf2.setEditable(false);

        tf3.setEditable(false);

        tf4.setEditable(false);

    }

 

    public void actionPerformed(ActionEvent e) {

        //Create DataBase Coonection and Fetching Records

 

        try {

            String str = tf5.getText();

 

            Class.forName("oracle.jdbc.driver.OracleDriver");

            Connection con = DriverManager.getConnection("jdbc:oracle:thin:@mcndesktop07:1521", "sandeep", "welcome");

            PreparedStatement st = con.prepareStatement("select * from emp where uname=?");

            st.setString(1, str);

 

            //Excuting Query

            ResultSet rs = st.executeQuery();

 

            if (rs.next()) {

                String s = rs.getString(1);

                String s1 = rs.getString(2);

                String s2 = rs.getString(3);

                String s3 = rs.getString(4);

 

                //Sets Records in TextFields.

                tf1.setText(s);

                tf2.setText(s1);

                tf3.setText(s2);

                tf4.setText(s3);

            } else {

                JOptionPane.showMessageDialog(null, "Name not Found");

            }

 

            //Create Exception Handler

        } catch (Exception ex) {

 

            System.out.println(ex);

        }

    }

//Running Constructor

 

    public static void main(String args[]) {

        new SwingSearchApp();

    }

}

this is my code
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Dimension;
import java.awt.*;
import javax.swing.JComboBox;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.JTabbedPane;
//import com.mongodb.MongoException;



public class CreateUserGUI extends JFrame{

    private static final long serialVersionUID = 1L;
	private JPanel backgroundPanel = null, backPanel = null, topPanel = null, bottomPanel = null, sidePanel = null;
	private JTextField txtName = null, txtSurname = null, txtUsername = null;
	private JPasswordField passwordField = null;
	private JLabel nameLabel = null, surnameLabel = null, usernameLabel = null, passwordLabel = null, statusComboLabel = null;
	private JButton btnSave = null, btnCancel = null, btnCreate = null, btnUpdate = null, btnDelete = null, btnSearch = null;
	private JComboBox<String> statusCombo = null;
	
	
	
	
	
	public CreateUserGUI()
	{
		
	//	backPanel = new JPanel(new GridBagLayout());
			backPanel = new JPanel(new  BorderLayout());
	//	topPanel = new JPanel(new GridBagLayout());
		JTabbedPane jtp = new JTabbedPane();
		getContentPane().add(jtp);
		
		
		
    	JPanel jp1 = new JPanel();
        JPanel jp2 = new JPanel();
        JPanel jp3 = new JPanel();
        JPanel jp4 = new JPanel();
		
	
		
		
		JLabel label1 = new JLabel();
        label1.setText("You are in area of creating new User");
        JLabel label2 = new JLabel();
        nameLabel = new JLabel("Name : ");
	    txtName = new JTextField(15);
		txtName.setMinimumSize(txtName.getPreferredSize());   	
	    surnameLabel = new JLabel("Surname : ");
	    txtSurname = new JTextField(15);
	    txtSurname.setMinimumSize(txtSurname.getPreferredSize());
	    usernameLabel = new JLabel("Username : ");
	    txtUsername = new JTextField(15);
	    txtUsername.setMinimumSize(	txtUsername.getPreferredSize());
	    passwordLabel = new JLabel("Password : ");
	    passwordField = new  JPasswordField(15);
	    passwordField.setMinimumSize(passwordField.getPreferredSize());
	    btnSave = new JButton("Save") {
	        {
	            setSize(5, 10);
	            //setMaximumSize(getSize());
	            setMinimumSize(getSize());
	        }
	    };
        
        
       // label1.setBounds(5,15,100,20);
        nameLabel.setBounds(1, 50, 150, 20);
	   	txtName.setBounds(70,50,150,20);
		surnameLabel.setBounds(1, 80, 150, 20);
		txtSurname.setBounds(70,80,150,20);
		usernameLabel.setBounds(1,110,150,20);
		txtUsername.setBounds(70,110,150,20);
		passwordLabel.setBounds(1, 140, 150, 20);
		passwordField.setBounds(70, 140, 150, 20);  
		btnSave.setBounds(70,160,80,20);	
			
        
        
        
        
        
        label2.setText("You are in area of Updating user Information");
        JLabel label3 = new JLabel();
        label3.setText("You are in area of seting  user Inactive");
        JLabel label4 = new JLabel();
        label4.setText("username ");
        statusComboLabel = new JLabel("Status : ");
		statusCombo = new JComboBox<>();
		statusCombo.addItem("Active");
		statusCombo.addItem("Inactive");
		label4.setBounds(1,50,150,20);
		statusCombo.setBounds(70,50,150,20);
		
        
        	
        
         
		
	    			
			
			
		
		
		/*txtName = new JTextField();
		txtSurname = new JTextField();
		txtUsername = new JTextField();
		passwordField = new JPasswordField();
		
		
		nameLabel = new JLabel("Name : ");
		surnameLabel = new JLabel("Surname : ");
		usernameLabel = new JLabel("Username : ");
		passwordLabel = new JLabel("Password : ");*/
		//****statusComboLabel = new JLabel("Status : ");
		
		
   	//topPanel.setLayout(null);
   //	bottomPanel.setLayout(new GridLayout(0,1));
		
		
    /*  topPanel.add(nameLabel);
      topPanel.add(txtName);
      topPanel.add(surnameLabel);
      topPanel.add(txtSurname);
      topPanel.add(passwordLabel);
      topPanel.add(passwordField);*/
      
      //jp1.setLayout(new GridBagLayout());
      //jp1.setLayout(new GridBagLayout());
      //jp1.setLayout(new GridLayout(2,2));
      
      jp1.setLayout(null);
      //jp1.setLayout(new GridBagLayout());
      jp2.setLayout(new GridBagLayout());
      jp3.setLayout(new GridBagLayout());
      jp4.setLayout(new GridBagLayout());
        jp1.add(label1);
        jp1.add(nameLabel);
        jp1.add(txtName);
        jp1.add(usernameLabel);
        jp1.add(txtUsername);
        jp1.add(surnameLabel);
        jp1.add(txtSurname);
        jp1.add(passwordLabel);
        jp1.add(passwordField);
        jp1.add(btnSave);
        
        jp2.add(label2);
        
        
        
        
        
        
        jp3.add(label3);
        jp4.setLayout(null);
        jp4.add(label4);
        jp4.add(statusCombo);
        
        
        
        
        jtp.addTab("create", jp1);
        jtp.addTab("update", jp2);
        jtp.addTab("Delete", jp3);
        jtp.addTab("Search", jp4);
		
	
		
	this.setTitle("Create User");
    this.setSize(600,450);
    this.setLocation(500, 280);
		
		
	Toolkit toolkit = getToolkit();
		
		Dimension size = toolkit.getScreenSize();
		
		setLocation(size.width/2 - getWidth()/2,
				size.height/2 - getHeight()/2);		
		
		
		
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//this.getContentPane().add(topPanel);
		
this.setVisible(true);
		
		
	
		
	}
	

Open in new window

0
chalie001Author Commented:
combox something like this when I list username and return theire details
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

chalie001Author Commented:
0
gurpsbassiCommented:
Ok that's some good information.

1)What is the name your collection on mongodb that contains the data you require?

2)can you describe what one of your BSON documents looks like in this collection?
0
chalie001Author Commented:
this is my collection
collection
0
chalie001Author Commented:
I require data from user collection
0
gurpsbassiCommented:
can you give me the output of db.system.users.findOne().pretty() ?
0
Tomas Helgi JohannssonCommented:
Hi!

I would implement a Listener for the ComboBox to respond to a change of a selected value.
Here are some examples to follow
http://www.java2s.com/Tutorial/Java/0240__Swing/ListentoJComboBoxwithItemListener.htm
http://www.java2s.com/Tutorial/Java/0240__Swing/ListeningforChangestotheSelectedIteminaJComboBoxComponent.htm

Regards,
    Tomas Helgi
0
gurpsbassiCommented:
would implement a Listener for the ComboBox to respond to a change of a selected value.

Unless I have misunderstood, the issue is with querying mongo and not the mechanics of event binding in Swing?  @chalie001 please confirm this.
0
chalie001Author Commented:
where do I run db.system.users.findOne().pretty() ?  I do have a gui
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Dimension;
import java.awt.*;
import javax.swing.JComboBox;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.JTabbedPane;
//import com.mongodb.MongoException;

/*import sita.co.za.auditTrail.LogFile;
import sita.co.za.common.UserDAO;
import sita.co.za.exception.DSNappException;
import sita.co.za.exception.ValidateData;
import sita.co.za.model.User;*/



public class CreateUserGUI extends JFrame{

    private static final long serialVersionUID = 1L;
	private JPanel backgroundPanel = null, backPanel = null, topPanel = null, bottomPanel = null, sidePanel = null;
	private JTextField txtName = null, txtSurname = null, txtUsername = null;
	private JPasswordField passwordField = null;
	private JLabel nameLabel = null, surnameLabel = null, usernameLabel = null, passwordLabel = null, statusComboLabel = null;
	private JButton btnSave = null, btnCancel = null, btnCreate = null, btnUpdate = null, btnDelete = null, btnSearch = null;
	private JComboBox<String> statusCombo = null;
	private JLabel sSurnameLabel = null,sPasswordLabel = null,SName = null;
	private JTextField sTxtname = null,sTxtSurname = null;
	private JPasswordField sTxtPassword  = null;
	
	
	
	
	
	public CreateUserGUI()
	{
		
	//	backPanel = new JPanel(new GridBagLayout());
			backPanel = new JPanel(new  BorderLayout());
	//	topPanel = new JPanel(new GridBagLayout());
		JTabbedPane jtp = new JTabbedPane();
		getContentPane().add(jtp);
		
		
		
    	JPanel jp1 = new JPanel();
        JPanel jp2 = new JPanel();
        JPanel jp3 = new JPanel();
        JPanel jp4 = new JPanel();
		
	
		
		
		JLabel label1 = new JLabel();
        label1.setText("You are in area of creating new User");
        JLabel label2 = new JLabel();
        nameLabel = new JLabel("Name : ");
	    txtName = new JTextField(15);
		txtName.setMinimumSize(txtName.getPreferredSize());   	
	    surnameLabel = new JLabel("Surname : ");
	    txtSurname = new JTextField(15);
	    txtSurname.setMinimumSize(txtSurname.getPreferredSize());
	    usernameLabel = new JLabel("Username : ");
	    txtUsername = new JTextField(15);
	    txtUsername.setMinimumSize(	txtUsername.getPreferredSize());
	    passwordLabel = new JLabel("Password : ");
	    passwordField = new  JPasswordField(15);
	    passwordField.setMinimumSize(passwordField.getPreferredSize());
	    btnSave = new JButton("Save") {
	        {
	            setSize(5, 8);
	            //setMaximumSize(getSize());
	            setMinimumSize(getSize());
	        }
	    };        
	    	
	  btnCreate = new JButton("Create"){
	  {
	  	setSize(5,8);
	  	setMinimumSize(getSize());
	  }
	  };  	
	    	
       // label1.setBounds(5,15,100,20);
        nameLabel.setBounds(1, 50, 150, 20);
	   	txtName.setBounds(70,50,150,20);
		surnameLabel.setBounds(1, 80, 150, 20);
		txtSurname.setBounds(70,80,150,20);
		usernameLabel.setBounds(1,110,150,20);
		txtUsername.setBounds(70,110,150,20);
		passwordLabel.setBounds(1, 140, 150, 20);
		passwordField.setBounds(70, 140, 150, 20);  
		btnSave.setBounds(70,160,80,20);	
		btnCreate.setBounds(140,160,80,20);	
        
        
        
        
        
        label2.setText("You are in area of Updating user Information");
        JLabel label3 = new JLabel();
        label3.setText("You are in area of seting  user Inactive");
        JLabel label4 = new JLabel();
        label4.setText("username ");
        statusComboLabel = new JLabel("Status : ");
		statusCombo = new JComboBox<>();
		//statusCombo.addItem("Active");
	//	statusCombo.addItem("Inactive");
		SName = new JLabel("Name");
		sTxtname = new JTextField(15);
		sTxtname.setMinimumSize(sTxtname.getPreferredSize()); 
		sSurnameLabel = new JLabel("Surname");
		sTxtSurname = new JTextField(15);
		sTxtSurname.setMinimumSize(sTxtSurname.getPreferredSize());
		sPasswordLabel = new JLabel("Password");
		sTxtPassword = new JPasswordField(15);
		sTxtPassword.setMinimumSize(sTxtPassword.getPreferredSize());
		
		
		
	/*	usernameLabel.setBounds(1, 30, 150, 20);
		usernameText.setBounds(70, 30, 150, 20);
		passwordLabel.setBounds(1, 65, 150, 20);
		passwordField.setBounds(70, 65, 150, 20);
		loginButton.setBounds(120, 110, 80, 20);*/
		
		
		
		
		label4.setBounds(1,30,150,20);
		statusCombo.setBounds(70,30,150,20);
		SName.setBounds(1,70,100,20);
		sTxtname.setBounds(90,70,150,20);
		sSurnameLabel.setBounds(1,90,150,20);
		sTxtSurname.setBounds(90,90,150,20);
		sPasswordLabel.setBounds(1,110,150,20);
		sTxtPassword.setBounds(90,110,150,20);
		
		
		
		
		
        
        	
        
         
		
	    			
			
			
		
		
		/*txtName = new JTextField();
		txtSurname = new JTextField();
		txtUsername = new JTextField();
		passwordField = new JPasswordField();
		
		
		nameLabel = new JLabel("Name : ");
		surnameLabel = new JLabel("Surname : ");
		usernameLabel = new JLabel("Username : ");
		passwordLabel = new JLabel("Password : ");*/
		//****statusComboLabel = new JLabel("Status : ");
		
		
   	//topPanel.setLayout(null);
   //	bottomPanel.setLayout(new GridLayout(0,1));
		
		
    /*  topPanel.add(nameLabel);
      topPanel.add(txtName);
      topPanel.add(surnameLabel);
      topPanel.add(txtSurname);
      topPanel.add(passwordLabel);
      topPanel.add(passwordField);*/
      
      //jp1.setLayout(new GridBagLayout());
      //jp1.setLayout(new GridBagLayout());
      //jp1.setLayout(new GridLayout(2,2));
      
      jp1.setLayout(null);
      //jp1.setLayout(new GridBagLayout());
      jp2.setLayout(new GridBagLayout());
      jp3.setLayout(new GridBagLayout());
      jp4.setLayout(new GridBagLayout());
        jp1.add(label1);
        jp1.add(nameLabel);
        jp1.add(txtName);
        jp1.add(usernameLabel);
        jp1.add(txtUsername);
        jp1.add(surnameLabel);
        jp1.add(txtSurname);
        jp1.add(passwordLabel);
        jp1.add(passwordField);
        jp1.add(btnSave);
        jp1.add(btnCreate);
        
        jp2.add(label2);
        
        
        
        
        
        
        jp3.add(label3);
        jp4.setLayout(null);
        jp4.add(label4);
        jp4.add(statusCombo);
        jp4.add(SName);
        jp4.add(sTxtname);
        jp4.add(sSurnameLabel);
        jp4.add(sTxtSurname);
        jp4.add(sPasswordLabel);
        jp4.add(sTxtPassword);
        
        
        
        jtp.addTab("create", jp1);
        jtp.addTab("update", jp2);
        jtp.addTab("Delete", jp3);
        jtp.addTab("Search", jp4);
		
	
		
	this.setTitle("Create User");
    this.setSize(600,450);
    this.setLocation(500, 280);
		
		
	Toolkit toolkit = getToolkit();
		
		Dimension size = toolkit.getScreenSize();
		
		setLocation(size.width/2 - getWidth()/2,
				size.height/2 - getHeight()/2);		
		
		
		
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//this.getContentPane().add(topPanel);
		
this.setVisible(true);
		
		
	
		
	}

Open in new window


yes the issue is qurying value from mongo db and display in my combobox
0
chalie001Author Commented:
db.system.users.findOne().pretty()  the users is table with all users and the details
the column are

id
name
surname
username
password
status
0
chalie001Author Commented:
i what something like this
import javax.swing.*;
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;//where do I get this am getting error is not recognise
import java.awt.*;

public class Demo {

    JFrame frame = new JFrame("");
    AutoCompleteDecorator decorator;
    JComboBox combobox;

    public Demo() {
        combobox = new JComboBox(new Object[]{"","Ester", "Jordi",
            "Jordina", "Jorge", "Sergi"});//I what to searc from database
        AutoCompleteDecorator.decorate(combobox);
        frame.setSize(400,400);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLayout(new FlowLayout());

        frame.add(combobox);
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        Demo d = new Demo();
    }
}

Open in new window


but quring value fron mongo db
0
gurpsbassiCommented:
to query your collection by username you would do :

public DBObject findByUsername(String username){
  DBCollection dbCollection = mongo.getDB("system").getCollection("users");
  DBObject criteria = new BasicDBObject("username", username);
  return dbCollection.findOne(criteria);
}

This will give you a DBObject containing the user BSON.

You now need to decide what you want to do with it? i.e. return it as it is to your front end or map it to another object? I'll let you decide.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chalie001Author Commented:
i what to populate the detail of that user
name
surname
password
0
gurpsbassiCommented:
Ok so I believe your original question was on how to query mongodb.

You are now asking further question on how to use the results of the query to populate the fields on your UI ?

Have I understood correctly?
0
chalie001Author Commented:
yes thats correct i already have gui
0
chalie001Author Commented:
this is my gui
gui
0
chalie001Author Commented:
correct
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.