Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / April 2004

Tip: Looking for answers? Try searching our database.

JComboBox question

Thread view: 
Milan - 04 Apr 2004 16:56 GMT
Hi all,

I have JComboBoxes A and B.

B depends on A (when I change selection in A, B should change also (it
should get news values from database, based on selected value in A)).

How can I update JComboBox B?

---
JComboBox aList = new JComboBox(aArray);
JComboBox bList = new JComboBox(bArray);
aList.addActionListener(new java.awt.event.ActionListener()
{
   public void actionPerformed(ActionEvent e)
   {

       ** I don't know what to write here :) **

   }
});
---
Michael Dunn - 04 Apr 2004 20:58 GMT
: Hi all,
:
[quoted text clipped - 18 lines]
: });
: ---

Here's something to play around with

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

class Testing extends JFrame implements ItemListener
{
 JComboBox aList, bList;
 String[] aText = {"Britain","France","Italy","USA"};
 String[][] bText = {{"Liverpool","London","Manchester"},{"Calais","Lyons","Paris"},
                     {"Florence","Rome","Venice"},{"Denver","Houston","New York"}};
 public Testing()
 {
   super("JComboBox Test");
   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   setSize(200,100);
   setLocation(400,300);
   Container frame = getContentPane();
   frame.setLayout(new FlowLayout());
   aList = new JComboBox(aText);
   aList.addItemListener(this);
   frame.add(aList);
   bList = new JComboBox(bText[0]);
   bList.addItemListener(this);
   frame.add(bList);
   setContentPane(frame);
 }
 public void itemStateChanged(ItemEvent ie)
 {
   if(ie.getSource() == aList)
   {
     bList.removeAllItems();
     int index = aList.getSelectedIndex();
     for(int x = 0; x < bText[index].length; x++) bList.addItem(bText[index][x]);
   }
 }
 public static void main(String[] args){new Testing().setVisible(true);}
}


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.