Home Discussion Discuss: Create a JComboBox Component in Java

  • JComboBoxJohn July 7, 2011 at 1:46 PM

    I am trying to create a JComboBox that has three options Yes,No and One months rent.If yes is selected then it will prompt the user to enter a amount.If no and one months rent is selected they go on to the next item. Thank you for your help. John

  • JComboboxhiwa November 11, 2011 at 2:59 AM

    hi please I want bay any index in combobox call one method e.x/ if i have combobox and have for index and in this combobox why i can call 4method by these 4index

  • combobox in swing JavaDarshan Rahate January 11, 2012 at 12:20 AM

    if we type any character in combo box then we get list of related character of word in combo box no other character of word.

  • thumbs up roseObed March 25, 2013 at 2:50 PM

    Good day..pliz help me to create the user inface that can view, add, delete, reset and update data in the sql server. The user should be able to select the id from the dropdow list and the data should be displyed on the combo with corresponding id. here is my code with the missing user interface. import java.awt.Font; import java.awt.GridLayout; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import javax.swing.*; import java.awt.event.*; import java.sql.*; public class ProductInfo extends JFrame implements ActionListener { //code user interface here// try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con= DriverManager.getConnection("jdbc:odbc:LecoDB", "sa","niit@123"); stmt = con.createStatement(); rs = stmt.executeQuery("SELECT EventID FROM Events"); while (rs.next()) { idCombo.addItem(Integer.toString(rs.getInt(1))); } con.close(); } catch(Exception e) { System.out.println ("error : "+e); } } @Override public void actionPerformed(ActionEvent ae) { if("Exit".equals(ae.getActionCommand())) System.exit(0); if("Delete".equals(ae.getActionCommand())) { try { con = DriverManager.getConnection("jdbc:odbc:LecoDB", "sa", "niit@123"); stat = con.prepareStatement ("DELETE from Event WHERE EventID = ?"); String selected_id = idCombo.getSelectedItem().toString(); int id = Integer.parseInt(selected_id); stat.setInt (1, id); stat.executeUpdate(); con.close(); idCombo.removeActionListener(this); con =DriverManager.getConnection("jdbc:odbc:LecoDB", "sa","niit@123"); stmt = con.createStatement(); rs = stmt.executeQuery ("SELECT p FROM Events"); idCombo.removeAllItems(); while (rs.next()) idCombo.addItem(Integer.toString(rs.getInt(1))); con.close(); idCombo.addActionListener(this); teventid.setText(""); teventname.setText(""); tstartdate.setText(""); tenddate.setText(""); tlocation.setText(""); tnoofpeople.setText(""); tstaffrequired.setText(""); error.setText("Row Deleted"); } catch (Exception e) { System.out.println ("Error" + e); error.setText("Row connot be Deleted"); } } if("insert".equals(ae.getActionCommand())) { try { con = DriverManager.getConnection("jdbc:odbc:LecoDB", "sa", "niit@123"); stat = con.prepareStatement("INSERT INTO Events VALUES(?, ?, ?, ?, ?, ?, ?)"); String id = teventid.getText(); String EventName= teventname.getText(); String StartDate = tstartdate.getText(); String EndDate = tenddate.getText(); String Location = tlocation.getText(); String NoOfPeople = tnoofpeople.getText(); String StaffRequired = tstaffrequired.getText(); stat.setInt(1, Integer.parseInt(id)); stat.setString(2, EventName); stat.setString(3, StartDate); stat.setString(4, EndDate); stat.setString(5, Location); stat.setString (6, NoOfPeople); stat.setString(7, StaffRequired); stat.executeUpdate(); con.close(); idCombo.removeActionListener(this); con=DriverManager.getConnection("jdbc:odbc:LecoDB", "sa", "niit@123"); stmt = con.createStatement(); rs = stmt.executeQuery("SELECT EventID FROM Events"); idCombo.removeAllItems(); while (rs.next()) idCombo.addItem(Integer.toString(rs.getInt(1))); con.close(); idCombo.addActionListener(this); error.setText("Row Inserted"); } catch (Exception e) { System.out.println("Error1" +e); error.setText("Rows cannot be inserted"); } } if(ae.getSource() == idCombo) { try { con = DriverManager.getConnection("jdbc:odbc:LecoDB", "sa", "niit@123"); String selected_id = idCombo.getSelectedItem().toString(); int id = Integer.parseInt(selected_id); stmt = con.createStatement(); rs = stmt.executeQuery("SELECT EventName, StartDate, EndDate, Location,NoOfPeople, StaffRequired FROM Events WHERE EventID =" +id); rs.next(); teventid.setText(selected_id); teventname.setText(rs.getString(1)); tstartdate.setText(rs.getString(2)); lenddate.setText (Integer.toString(rs.getInt(3))); tlocation.setText(rs.getString(4)); tnoofpeople.setText(rs.getString(5)); tstaffrequired.setText(rs.getString(6)); con.close(); } catch (Exception e) { System.out.println ("Error " +e); } } if("Update".equals(ae.getActionCommand())) { try { con = DriverManager.getConnection("jdbc:odbc:LecoDB", "sa", "niit@123"); stat = con.prepareStatement("UPDATE Events SET EventID =?, Location = ?, StartDate= ?, EndDate =?, NoOfPeople, StaffRequired where p_id = ?"); String EventName = teventname.getText(); String StartDate = tstartdate.getText(); String EndDate = tenddate.getText(); String Location= tlocation.getText(); String NoOfPeople= tnoofpeople.getText(); String StaffRequired= tstaffrequired.getText(); String id_selected = teventid.getText(); int id = Integer.parseInt(id_selected); stat.setString(1, EventName); stat.setDouble(2, Double.parseDouble(StartDate)); stat.setDouble(3, Double.parseDouble(EndDate)); stat.setString(4, Location); stat.setString(5, NoOfPeople); stat.setString(6, StaffRequired); stat.setInt(5, id); stat.executeUpdate(); con.close(); error.setText( "Row Updated"); } catch (Exception e) { System.out.println("Error " + e); error.setText("Cannot update the row"); } } if ("clear".equals(ae.getActionCommand())) { teventid.setText(""); teventname.setText(""); tstartdate.setText(""); tenddate.setText(""); tlocation.setText(""); tnoofpeople.setText(""); tstaffrequired.setText(""); } } public static void main (String args[]) { ProductInfo p; p =new ProductInfo(); frame.setSize (400, 550); frame.setVisible(true); } }

  • JAVAMOLLY June 27, 2013 at 3:58 PM

    output to de hi ni rkhi program ki,coding b glt h, ye kya bna rkha h. Program dhang k with correct coding upload kia kro.........

  • :)Plamen June 24, 2013 at 10:13 AM

    Very useful, thank you

  • javavenky cam July 24, 2013 at 2:32 PM

    this language is very diffculty.

  • javacam July 24, 2013 at 2:36 PM

    this language vr deffrent

  • jcombobox listenerRachel December 17, 2011 at 11:47 AM

    how exactly would i go about writing a listener if i have a combo box with book genres and i want (depending on the genre selected), selected books of that genre to be shown in a JList (so that when the user selects one of the books, an image of the book is shown). so what listener do i use? action or item listener? and how to i write it? with "if" statements??

Post your Comment



Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Related Articles
Java-Tutorials

Create a JComboBox Component in Java
Create a JComboBox Component in Java       In this section, you will learn about the JComboBox Component of swing in java. The JComboBox is used to display drop-down list 

Java Beginners

JComboBox on JRadioButton - Java Beginners
JComboBox on JRadioButton  How to add JComboBox on Jpanel ,Give Me Sample Code 

Java Tips and Examples

JComboBox - Tutorial on JComBoBox
Java: JComboBox (uneditable) Making Choices There are several ways..., or a (uneditable) combo box. A combo box (JComboBox) is a popup menu and is often the best component to use because it uses less space than radio 

Java Beginners

JComboBox with AccessDatabase - Java Beginners
JComboBox with AccessDatabase  Hello Sir I have Created Course... on Student Admission Form when I select Course Name from JComboBox on Student... = new JFrame("Frame in Java Swing"); f.getContentPane().setLayout(null); JLabel 

Java Beginners

JComboBox Event Handling - Java Beginners
JComboBox Event Handling  Hi, I have problem with event handling here.There are Two JComboBox and a JTextField.When I select an item in first... Compare extends JFrame implements ItemListener { JComboBox combo,lcombo 

Java Beginners

JComboBox
JComboBox  I want to change the index of one jComboBox according to the selected index of another jComboBox. I can do it.Also the user should have the ability to select or change the index of the second combobox according 

Java Beginners

jComboBox
jComboBox  I want to change the index of one jComboBox according to the selected index of another jComboBox. I can do it.Also the user should have the ability to select or change the index of the second combobox according 

Java Beginners

JComboBox
JComboBox  I have jcombobox. In which tha values are loaded from MySql Database. My problem is that i want to load content of the jtable whenever i change the selected item. Please some one help me to do this. Thank you 

Java Beginners

jcombobox
jcombobox  hi i have developed a form and i have jcombobox in which data is retrieved from ms access but the problem is that if we pressed the down key the last 5 data are not showed only the other data can be pressed 

Java Beginners

JComboBox
have jcombobox on Jframe form of IDE. In which the values are to be loaded from... change the selected item in JComboBox. Thank you.   import java.sql....); JLabel lab=new JLabel("Select"); final JComboBox combo=new JComboBox 

Java Beginners

problem with addactionlistener on JComboBox - Java Beginners
[] = { "A", "B", "C"}; JFrame frame = new JFrame(); JComboBox combo = new JComboBox(st); frame.add(combo); ActionListener actionListener = new 

Java Beginners

Changing JLabel with a jcombobox - Java Beginners
listener event of JComboBox put JLabel.setText("Put yourtext here 

Java Beginners

Link To Database with JComboBox - Java Beginners
course names from Access Database in to JComboBox but now I want to do ,when i select Course name from Jcombobox i want to display appropriate records relate... SwingFrame(); } public SwingFrame(){ JFrame f = new JFrame("Frame in Java Swing 

Java Beginners

JComboBox Display Problem - Java Beginners
JComboBox Display Problem  I am create one program that contain two...,ItemListener { Container c; JLabel lblstart,lblend; JComboBox cmbstart..."); lblend=new JLabel("End Date"); cmbstart=new JComboBox(); cmbend=new 

Java-Tutorials

Combo box In Java
Combo box In Java This tutorial will help you to create a Combo box in java... a value in the editable field. Combo box can be created using JCombobox in java.... Constructor of JCombobox are as follows: JComboBox() : Create a combo box 

Java Interview Questions

Java component
Java component  What is the preferred size of a component 

Java Beginners

How to Add JComboBox on JPanel - Java Beginners
How to Add JComboBox on JPanel  How to Add JComboBox on JPanel D...(){ JFrame f = new JFrame("Frame in Java Swing"); f.getContentPane().setLayout(null...); JLabel lbl4=new JLabel("Branch"); final JComboBox jc=new JComboBox(); jc.addItem 

Swing AWT

easy way to make a JCombobox look like a JTextField?
easy way to make a JCombobox look like a JTextField?  Is there a good(and easy) way to make a JCombobox look like a JTextField? By this I mean.... works   Autosuggestion box in Java Swing 

Java Interview Questions

Java component class
Java component class  Which method of the Component class is used to set the position and size of a component 

Java Beginners

Add Items in JComboBox from Access Database - Java Beginners
Add Items in JComboBox from Access Database  Heelo Sir I want To add ittem in JComboBox which is stored in Access Database. plz Help Me Sir... records in to my JComboBox.   Hi Friend, Try the following code 

Java Beginners

How to store JComboBox selected Item into Ms Access Database - Java Beginners
How to store JComboBox selected Item into Ms Access Database  How to store JComboBox selected Item into Ms Access Database.  Hi Friend...(); } public SwingFrame(){ JFrame f = new JFrame("Frame in Java Swing 

Java Beginners

How to save JCombobox Selected Item in to Access Database - Java Beginners
How to save JCombobox Selected Item in to Access Database  How to save JCombobox Selected Item in to Access Database  Hi Friend, Try... SwingFrame(){ JFrame f = new JFrame("Frame in Java Swing"); f.getContentPane 

Java-Tutorials

JComboBox Insert Edited Value Into Table
in to insert an editable value of JComboBox into a table. We will use an Java editor...) and then we will create a class in Java inside which we will create a frame using...JComboBox Insert Edited Value Into Table In this section we will read about 

Java Beginners

Load Coursenames from MS Acess Database to JComboBox - Java Beginners
in Java Swing"); f.getContentPane().setLayout(null); JLabel lbl1 = new JLabel..."); final JComboBox jc=new JComboBox(); try{ Class.forName 

Java Beginners

Container or Component - Java Beginners
about the realtionship between Components and Containers in Java GUI? 1) a component is a subclass of a container which means any container can hold a component 2) a component is allowed to hold other components including containers. 3 

Java-Tutorials

Java JComboBox Get Selected Item Value
Java JComboBox Get Selected Item Value In this section we will discuss about how to get the selected item value form JComboBox. javax.swing.JComboBox... of JComboBox into the database table. To store the selected item value of JComboBox 

Java Beginners

Component gui - Java Beginners
Component gui  Can you give me an example of Dialog in java Graphical user interface?  Hi friend, import javax.swing.*; public...://www.roseindia.net/java/example/java/swing/ Thanks 

Swing AWT

navigation between panels when item is selected from jcombobox - Swing AWT
on JComboBox in Java visit to : http://www.roseindia.net/java/example/java/swing 

Swing AWT

issue on jcombobox
issue on jcombobox  i have JTextfield and JComboBox. there are several values in combobox.when i select a value from combobox how to make textfiled as a combobox.only few values in the combobox need this functionality. need 

JDBC Questions

jComboBox with database
jComboBox with database  Hello friends, I have created three JComboBoxes. first two of them get list from string. However I select these two comboboxes, the third combobox automatically retrieve data of a particular column from 

DMCA.com