Solved

Items in a Choice

Posted on 1998-11-11
6
196 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
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now