473,511 Members | 16,756 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JComboBox help

51 New Member
I am trying to use comboboxes in a ticket payment screen for train tickets. I have two combo boxes. One for picking a route and the other for picking a time. What i want is when you pick a route in the first combo box, different departure times are availble in the time combobox depending on your route choice. I am trying to use if statements but its not working.

[JAVA = CODE]

routesCmb = new JComboBox();
routesCmb.addItem("Please pick a route");
routesCmb.addItem(route);
routesCmb.addItem(route2);
timesCmb = new JComboBox();
timesCmb.addItem("Please pick a time");
if routesCmb.SelectedItem(route);
{
timesCmb.addItem("3.00")
times.addITem("5.00")
}

[/code]
Mar 9 '08 #1
2 1626
sukatoa
539 Contributor
I am trying to use comboboxes in a ticket payment screen for train tickets. I have two combo boxes. One for picking a route and the other for picking a time. What i want is when you pick a route in the first combo box, different departure times are availble in the time combobox depending on your route choice. I am trying to use if statements but its not working.

[JAVA = CODE]

routesCmb = new JComboBox();
routesCmb.addItem("Please pick a route");
routesCmb.addItem(route);
routesCmb.addItem(route2);
timesCmb = new JComboBox();
timesCmb.addItem("Please pick a time");
if routesCmb.SelectedItem(route);
{
timesCmb.addItem("3.00")
times.addITem("5.00")
}

[/code]
In the if statement, no selectedItem method exists, maybe

getSelectedItem() - return's an object... Could be compared to String. Useful
getSelectedIndex() - return's an element, depends on current
selected item... nth...


Update us,
Sukatoa
Mar 9 '08 #2
BigDaddyLH
1,216 Recognized Expert Top Contributor
While there are multiple things wrong with the code you posted, the biggest mistake, I believe, is a failure to appreciate the event-driven paradigm.

You need to write a listener that is notified when the user makes a selection from the first combo box. Your code seems to believe it can pause execute until the user does something, which is not how GUI code works.

Why not read Sun's tutorial on Swing, especially on event handling?

http://java.sun.com/docs/books/tutor...nts/index.html
Mar 10 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
3011
by: L L | last post by:
Dear all, Is it possible to set selected item a table row or in other ways, the editable JComboBox 's JTextField- can that be replace by a one row table? If possible, any direction of what...
3
4709
by: Hal Vaughan | last post by:
I have a JComboBox with a list of numbers, from 1 digit to 5 digits. Numbers with more than 3 digits have a comma in them. I've been aligning them with leading spaces. Is there any simple and...
0
3228
by: Yasser | last post by:
Hi All, I developed an application (JFrame) to connect to mysql database. The application will select price from itemsTable and add each each item to a JComboBox. If the user change the prices in...
1
9885
by: Robert | last post by:
When I select a normal cell with a default editor for strings and press a letter key, the letter is automaticaly typed in the cell, but when I select a cell with an editable JComboBox editor and...
2
9905
by: jerico | last post by:
Hi, I am developing an application for which I need to increase the size of the JComboBox.But it is not getting increased.I used the following technique: Container cont; JComboBox valueTypeBox ;...
2
1747
jeffbroodwar
by: jeffbroodwar | last post by:
Hi, I tried to use JCombobox (i'm using netbeans 5.5) how can i use this jComboBox1? how can i load elements? I tried this code but i'm receiving errors.... ...
8
1856
by: dycharles | last post by:
I have a JComboBox loaded with 20,000 data, my problem is when i scroll down or scroll up, it is slower than the JComboBox with the smaller data. What can i do to make my JComboBox run faster or like...
2
2859
by: thesti | last post by:
hi, How to, if user change the selected item of a JComboBox, it will enable another JComboBox. it's like a validation that the user has to select the year first, then the month, than the date. ...
2
8697
by: HaifaCarina | last post by:
i have this unfinished java program and i can't figure out what is the problem.. please help... /** * @(#)Answer3.java * * * @author * @version 1.00 2008/1/17
0
7242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7138
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7355
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7423
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7081
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7510
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5668
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3213
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1576
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.