Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Items in a Choice

Posted on 1998-11-11
6
Medium Priority
?
203 Views
Last Modified: 2010-03-30
Suppose that there are two items in the Choice c: A and B .
How can I create a subItem list for B  when the user selects
the item B, and then add the one the user selected in the
subItem list to the Choice c? For example: the user selects
"Custom", then the items of the subitem list would be all customs
in the database. Please give an example code. Thanks!
0
Comment
Question by:leeann
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Expert Comment

by:mintt
ID: 1227243
Clue
use itemListener under jdk1.1
0
 
LVL 5

Expert Comment

by:msmolyak
ID: 1227244
Can you use popup menus instead (like the one you get when you click with your right mouse button in Windows Explorer)? There it is easy to create submenus and display them as a popup menu of the lower level.
0
 

Author Comment

by:leeann
ID: 1227245
Hi, Msmolyak:
Your suggestion sounds good, but how to let  the user know  they should select an item in the popup menus instead of the item B itself in the
Choice c.  One way I can let them know, for example:
 Change "Custom" ----> "Custom (using right mouse button)".
If the user makes a mistake, how to prevent the "Custom (using right mouse button) becomes the one selected item in the Choice c?
I would appreciate your help if you could write codes to solve these problems. By the way, I use JDK1.1.6. My program is a java application,
not an applet.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:msmolyak
ID: 1227246
JDK 1.1 should have support for popup menus, though I implemented them using Swing where I know for sure that method works.

Anyway, when you create a popup menu (java.awt.PopupMenu) you normally use MenuItem class to define menu items. But for the items which have submenus use Menu class instead (which is a subclass of a MenuItem). And add menu items to that menu.

E.g.,

PopupMenu popup = new PopupMenu();
popup.add(new MenuItem("A"));
Menu menu = (Menu)popup.add(new Menu("B"));
menu.add (new MenuItem("Second Level Item"));

and so on.

I do not think the GUI will allow you to select a menu item which has submenus, it will force you to select from the next level menu.
0
 

Author Comment

by:leeann
ID: 1227247
Sorry, I still don't know how to let this work for my case.  In my project,
I need a registration form for customs. So I create a registration frame
which includes some text fields, check boxes and Choices. In order to
manage these data in database, I also create buttons: Reflush, Save,
Search and Delect. When the user opens the registration frame, the
popup menu should not be shown immediately. Only when the user need
select an item in the popup menu. There are two things I don't know how
to deal with:
1. If use a popup menu instead of a Choice, how to display the result of a search?
2.  If use a popup menu instead of a Choice, the user doesn't know to select item in the popup menu which is not visible.

So I think a better way is to uses a Choice.
frame?
0
 
LVL 7

Accepted Solution

by:
conick earned 280 total points
ID: 1227248

I dont believe you can have sub-choices (like a tree structure or subMenuItems like a popup can)

what you may want to do is create another choice that is not visible and only appears when a certain value in your original Choice is given (namely "Custom")

you can create the Choice and make it invisible like the following:
Choice c= new Choice();
//add whatever initial values you want for you choice
c.setVisible(false);

Then you can add an event handler to your choice and when the "Custom" choice is selected
then make c visible:
c.setVisible(true)

You can add an event handler to c and do whatever you want to do with the selected value -- like add it to your original choice with the add() method
I didnt quite catch what exactly you want to do with the selected custom choices


0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question