JComboBox Event Handling

JComboBox Event Handling

View Answers

July 1, 2009 at 5:51 PM

Hi Friend,

Try the following code:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Compare extends JFrame implements ItemListener
{
JComboBox combo,lcombo;
JTextField number;

public Compare()
{
setLayout(null);
String a[]={"Select","First","Second"};

combo=new JComboBox(a);combo.setBounds(50,50,100,20);
combo.addItemListener(this);
add(combo);

lcombo=new JComboBox();
lcombo.addItemListener(this);lcombo.setEnabled(false);
add(lcombo);lcombo.setBounds(50,100,100,20);

number=new JTextField(5);number.setEditable(false);
add(number);number.setBounds(50,150,100,20);
setSize(300,300);
}

public void itemStateChanged(ItemEvent e) {
String b[]={"Select","One","Two"};
String c[]={"Select","Three","Four"};
if(e.getSource() == combo) {
if(combo.getSelectedItem().equals("Select"))
{
lcombo.setEnabled(false);
number.setEditable(false);
}
else if(combo.getSelectedItem().equals("First"))
{

lcombo.setEnabled(true);
number.setEditable(true);

for(int i=0;i<b.length;i++)
{
lcombo.removeItem(b[i]);
lcombo.removeItem(c[i]);

lcombo.addItem(b[i]);

}

}

else if(combo.getSelectedItem().equals("Second"))
{

lcombo.setEnabled(true);
number.setEditable(true);

for(int i=0;i<c.length;i++)
{
lcombo.removeItem(c[i]);
lcombo.removeItem(b[i]);

System.out.println(c[i]);
lcombo.addItem(c[i]);

}
}
}
else if(e.getSource() == lcombo) {
if(lcombo.getSelectedItem().equals("Select"))
{
number.setText("");number.setEditable(false);
}
else if(lcombo.getSelectedItem().equals("One"))
{
number.setText("1");number.setEditable(true);
}
else if(lcombo.getSelectedItem().equals("Two"))
{
number.setText("2");number.setEditable(true);
}
else if(lcombo.getSelectedItem().equals("Three"))
{


number.setText("3");number.setEditable(true);
}
else if(lcombo.getSelectedItem().equals("Four"))
{
number.setText("4");number.setEditable(true);
}
}
}
public static void main(String args[])
{
(new Compare()).setVisible(true);
}
}
Thanks









Related Tutorials/Questions & Answers:
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
event handling
event handling  diff btwn event handling in ASP.net and in HTML
Advertisements
handling Button Event in iphone
handling Button Event in iphone  handling Button Event in iphone
Event handling on an image
Event handling on an image  I want to divide an image into frames and want to do event handling on the frames
Java event handling
Java event handling  Which java.util classes and interfaces support event handling
javascript event handling examples
javascript event handling examples  javascript event handling examples   var handleClick = function(e) { // Older IEs set the `event... event listeners. document.attachEvent('onclick', handleClick); } else
Event handling - Java Beginners
Event handling  Hi, This is a similar kind of question i had asked before, with a little difference. Two JCombobox and a JtextField. When I select... ItemListener { JComboBox combo,lcombo; JTextField number; public Compare
event handling in jsp
event handling in jsp  i am developing a web application. i am getting a problem in event handing in jsp. in this web application there is a file... to generate event on each row of retrieved row from the database
Java event handling
Java event handling  What event results from the clicking of a button
Java event handling
Java event handling  What is the purpose of the enableEvents() method
KEY EVENT HANDLING
KEY EVENT HANDLING  I am trying to write a program that receives every key stroke even when the window is not active or it's minimized. Is there anyway to do
Event Handling - Java Beginners
Event Handling  import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Calculator extends JFrame { JLabel lblNumber=new JLabel("Number"); JLabel lblSquareRoot=new JLabel("Square Root
What are events? Explain how Event handling in Java?
What are events? Explain how Event handling in Java?  What are events? Explain how Event handling in Java?   Hi, The Events..., and introduces us to AWT event handling. For Details about Event Handling in Java
Event Handling In Java
Event Handling In Java In this section you will learn about how to handle.... In Java event handling may comprised the following four classes : Event Sources... that happens and your application behaves according to that event. For example
Understanding the jQuery event handling mechanism
Understanding the jQuery event handling mechanism... handling mechanism First of all , you need to know -What is an event... to handle these event. Event handling methods basically associates an event
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
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
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
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
how to add audio clip in swings with event handling
how to add audio clip in swings with event handling  hello dear, i wanna to play audio clip in java program in JFrame in swings by event handling ,it should be like when i click on a button , audio clip should play , plz tell me
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. (adsbygoogle... JLabel("Select"); final JComboBox combo=new JComboBox
Jcombobox
Jcombobox  Hii, I am doing my final year project and i am using java swing as a front end.I have used Jcombobox for displaying my on bluetooth devices and i also made a refresh button.when i click on the refresh button i
J2ME Event Handling Example
J2ME Event Handling Example       In J2ME programming language, Event Handling are used to handle certain... event like selecting an item from a listADS_TO_REPLACE_1 And low level events like
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
Handling Key Press Event in Java
Handling Key Press Event in Java   ... the handling key press event in java. Key Press is the event is generated when you press any key to the specific component. This event is performed by the KeyListener
how to open a web page using proxy in java and handling button event in that web page..?
how to open a web page using proxy in java and handling button event in that web page..?  Sir, what i need is a code which uses proxy address and opens a web page i.e for example and then clicks a "yes" button in that page
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
JComboBox on JRadioButton - Java Beginners
JComboBox on JRadioButton  How to add JComboBox on Jpanel ,Give Me Sample Code
Handling Mouse Clicks in Java
Handling Mouse Clicks in Java       Introduction In this section, you will learn about handling the mouse click event in the awt application. This program simply implements
Changing JLabel with a jcombobox - Java Beginners
listener event of JComboBox put JLabel.setText("Put yourtext here
Help on database and JComboBox
Help on database and JComboBox  I want to select from the JComboBox and when click onto the "search" button, the selected category (example "new york") all the each new york picture and detail will be seen. But how to grab
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..."); JComboBox combo1=new JComboBox(); JComboBox combo2=new JComboBox
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 with taht course on combobox item changed event. eg when i select MCA the fees
Create a JComboBox Component in Java
by the addItemListener() method of the JComboBox class. The event is generated... Create a JComboBox Component in Java       In this section, you will learn about the JComboBox
About jcombobox - Swing AWT
About jcombobox  Hi all, I am new to this forum. Can we do auto suggest jcombobox in swing? If yes is there any jar file for that or any code... JTextField tf; private final JComboBox combo = new JComboBox(); private
exception handling
exception handling  explain about exception handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  could you please tell me detail the concept of exception handling
File Handling
File Handling  how we do file handling of parsed XML code bu DOM in java
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
exception handling
exception handling   Give the exception hierarchy of Java.   Please visit the following links: http://www.roseindia.net/java/java-exception/exception-java.shtml http://www.roseindia.net/java/exceptions/exception

Ads