swings

swings

i have two combobox.In first combo box i have 5 items.If i selecte the first combo box item then the related data will apear in the second combo box, if i select the another item in the first combobox then the related data will appear in the second combo box. how can i acheive this.
thank you
View Answers

January 31, 2010 at 9:06 PM

Hi there mate...

I had tried to solve your question, but somehow this Combo Box seems like not reacting to the user events that nicely. Once you select a certain value
for one combo box ,, you need to click the combobox again to let that value pass onto the second combobox. But hope that might solve your problem.
If the problem persists, please do refer me back. Hope i can be of some help.

The Code is used is this :

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

public class TestCombo implements MouseListener{

private JFrame frame;
private JPanel panel;
private JComboBox cBox1;
private JComboBox cBox2;

public TestCombo() {

frame = new JFrame("Combo Test : ");
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
panel = new JPanel();
cBox1 = new JComboBox();
cBox2 = new JComboBox();

cBox1.addMouseListener(this);
cBox2.addMouseListener(this);
}

public void launchApp() {

frame.add(panel);

for (int count = 0; count < 5; count++)
cBox1.addItem(Integer.toString(count));

for (int count = 0; count < 5; count++)
cBox2.addItem(Integer.toString(count));

panel.add(cBox1);
panel.add(cBox2);

frame.pack();
frame.setVisible(true);
}

public void mouseClicked(MouseEvent me) {

JComboBox cBox = (JComboBox)me.getSource();

if (cBox == cBox1) {

frame.setVisible(false);
frame.remove(panel);
cBox2.setSelectedItem(cBox1.getSelectedItem());
frame.add(panel);
frame.setVisible(true);
}
else if (cBox == cBox2) {

frame.setVisible(false);
cBox1.setSelectedItem(cBox2.getSelectedItem());
frame.setVisible(true);
}
}

public void mouseReleased(MouseEvent me) {
}

public void mouseEntered(MouseEvent me) {
}

public void mouseExited(MouseEvent me) {
}

public void mousePressed(MouseEvent me) {
}

public static void main(String[] args) {

TestCombo tc = new TestCombo();
tc.launchApp();
}
}

February 1, 2010 at 11:36 AM

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;

public Compare(){
setLayout(null);
String a[]={"Select","Watches","Mobiles","shoes"};
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);

setSize(300,300);
}

public void itemStateChanged(ItemEvent e) {
String b[]={"Select","Titan","HMT"};
String c[]={"Select","Nokia","Sony","Motorola","Samsung"};
String d[]={"Select","Liberty","Action","Bata","Campus","Relaxo"};

if(e.getSource() == combo) {
if(combo.getSelectedItem().equals("Select")){
lcombo.setEnabled(false);
}
else if(combo.getSelectedItem().equals("Watches")){
lcombo.setEnabled(true);
lcombo.removeAllItems();
for(int i=0;i<b.length;i++){
lcombo.addItem(b[i]);
}
}
else if(combo.getSelectedItem().equals("Mobiles"))
{
lcombo.setEnabled(true);
lcombo.removeAllItems();
for(int i=0;i<c.length;i++){
lcombo.removeItem(c[i]);
lcombo.addItem(c[i]);
}
}
else if(combo.getSelectedItem().equals("shoes")){
lcombo.setEnabled(true);
lcombo.removeAllItems();
for(int i=0;i<d.length;i++){
lcombo.addItem(d[i]);
}
}
}
}
public static void main(String args[])
{
(new Compare()).setVisible(true);
}
}

Thanks









Related Tutorials/Questions & Answers:
SWINGS
SWINGS  WHAT ARE THE DIFFERENCES BETWEEN AWT AND SWINGS
JSP & Swings
JSP & Swings  How to integrate jsp and swings
Advertisements
swings question
swings question  how to change the background color with the help of color values by using swings
swings for webnms
swings for webnms  if i am expanding node of jtree then i want to collapse previous expanding node of jtree in swings how is it possible
Swings JTable
Swings JTable  add values to JTable with four coloums,two of them are comboboxes
Swings & JSP
Swings & JSP  Hai all, Can we use Swing components in a JSP?? Suppose if we enter details in a swing dialog box..and If we want the result in a JSP..is that possible??? Thank you
Java Swings
Java Swings  I am doing one project on java Swings, in this i have created one jframe where i defined some JButtons and Jcombobox's, here i need to insert one JTable with headers(IN CURRENT JFrame only).pls help me urgently
swings header
swings header   have a string1 it contains 3 parts,for example "123456 service hello" and string2 contains text "change request " like this. and the string3 should contain "123456 +(second string)+ hello" "second string can
swings
","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}; for(i = 0
swings
swings
swings
swings
swings
swings
Swings and JDBC
Swings and JDBC  Hi.. I am vinay.. I am developing a small application using swings and mysql. I am sending part of the code here.. The problem is i need to update the mysql fields with values which are gettin from dynamiclly
Swings - Applet
Swings  Sir, I have developed an application in swings i want to call that class in applet. is it possible. or otherwise is there any way to deploy java class in browser. Give an example... Thanks in advance...  Hi
Image Movement using Swings
Image Movement using Swings  How to move image using Swings
java swings - Java Beginners
java swings   Do you want to add textfields on the JPanel
how to create frame in swings
how to create frame in swings  how to create frame in swings
Swings/awt - Swing AWT
Swings/awt  Hi, how to write action listeners to the Buttons in RichTextEditor tool bar.. thanks in advance...it's Urgent... i am very much new to Swings
java code using swings
java code using swings  code that should be able to enter data of student details using all swings into the access database using jdbc connectivity
java swings - Java Beginners
java swings   Hi, I need the code for click the refresh button then list values will be refresh.Please send the code ........... Thanks, Valarmathi
An application using swings and vector methods
An application using swings and vector methods   Hi, I want an application in Java swings which uses good selection of Vectors methods
about swings - Java Beginners
about swings   Dear sir,Good evening, i am doing mca sir,i am doing the project in swings,so plz provide the material about swings sir Thank you  Hi Friend, Please visit the following link
java swings - Java Beginners
java swings   Hi, I need the code for joptionpane with jcombobox. my requirement is click on add button,one joptionpane will come.from the option pane i need to select the combobox values. Please send the sample code
java swings - Swing AWT
java swings  I am doing a project for my company. I need a to show the performance of the employees by using bar bharts. Please give me how can we write the code for bar charts using java swings.  Hi friend, I am
swings window header
swings window header  i have a string1 it contains 3 parts,for example "123456 service hello" and string2 contains "change request " like this. and the string3 should contain "123456 "........." hello" ".........." can
making of dynamic textfields using swings
making of dynamic textfields using swings  How to make dynamic textfields using java swings
another frame by using awt or swings
another frame by using awt or swings  how to connect one frame to another frame by using awt or swings
how can we store the encrypted passwaord in swings?
how can we store the encrypted passwaord in swings?   how can we store the encrypted passwaord in swings
java swings - Java Beginners
java swings   Hi, I already posted the question for three times.... I have two listboxes.If i select first value in the first listbox and moved to second listbox.The next time the same value will not able to move the first
java swings - JavaMail
java swings  Hi sir,i am doing a project on swings,i don't have any knowledge about the layoutmanagers,so my project is very very burden to me,so plz provide a material to me for understand the layout manager easily,plz help me
AWT-swings tutorial - Swing AWT
AWT-swings tutorial  hello sir, i am learnings swings and applets.. i want some tutorials and some examples related to swings.. thank you sir..waiting for your answer.  Hi friend, I am sending you a link
java swings - Java Beginners
java swings   Hi, I have two classes(two tabbed panes). how can i get the one class jtextfield value into another class method. Please send the code as sson as possible. Thanks, Valarmathi  Hi Friend, Try
swings - Java Beginners
swings  how to add an image to combobox? i searched for this in google, but i got very difficult programs. i am beginner in java swings . i want a small example to add a image .gif file to combobox list. thank you   Hi
swings - Java Beginners
swings  how to upload images using swings   Hi Friend, Try the following code: import java.awt.*; import java.io.*; import javax.swing.*; import java.awt.image.*; import java.awt.event.*; import
difference between applet and swings
are rectangular 5) Swings components are made in pure java and they are platform
Beans in Swings table
Beans in Swings table  Hi Sir/Madam.... I am Trying Develop an Swing from which include an table which displays the data from mysql table and i am adding one Jtextfield in each row in the last column and i want to update
swings - Java Beginners
swings   how t upload images in swings. thanks   Hello Friend, Try the following code: import java.io.*; import java.sql.*; import java.util.*; import java.awt.*; import java.awt.event.*; import
java swings - Java Beginners
java swings   Hi, This is my code. How can i set the jtextfield validation in numeric value only. Please change the code.If i insert otherthan number it displays error message. package com.zsl.ibm.mqtool; import
java swings - Java Beginners
java swings   Hi , I have two listboxes.I want to move one listbox value into another listbox using add button. I have the code....Please check this.I can't able to move the values from listbox into another one. Please
java swings - Java Beginners
java swings   hi, I posted the same question two times,but i didnt get the reply. Please change the jframe look and feel type of code.please send the code immediately. This is my code package com.zsl.ibm.mqtool; import
Java Swings-awt - Swing AWT
Java Swings-awt  Hi, Thanks for posting the Answer... I need to design a tool Bar which looks like a Formating toolbar in MS-Office Winword(Standard & Formating) tool Bar. Please help me... Thanks in Advance
Swings JTable numberic sorting - Swing AWT
Swings JTable numberic sorting  Hi , i am using jdk1.6 for my project and jdk1.6 is providing by default sorting of text column in JTable or suggestion for sorting of numberic column in JTable of Swings...Swings JTable numberic
Java Swings problem - Swing AWT
Java Swings problem  Sir, I am facing a problem in JSplitPane. I want the divider in the splitpane to be customized. I have a splitpane with Horizontal orientation and here, there lies the divider between left component and right
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
please send me the banking data base in swings
please send me the banking data base in swings  sir, please send me how to create the banking data base program in swings
Swings Menu Bar - Java Beginners
Swings Menu Bar  Hello, I created a menu bar using Java Swings... n New Record, Edit Record etc are the menu items. Now, I want to display the appropriate fields according the menu Item selected..below it.. i.e. If we
How to create XML from Swings
How to create XML from Swings  How to create XML using Swings. I have a Swing GUI and capturing all data from it.When i click on submit, an xml should be created with proper binding for all the elements. < Student > <

Ads