Solved

Items in a Choice

Posted on 1998-11-11
6
200 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
Industry Leaders: 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 70 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

752 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