Solved

Items in a Choice

Posted on 1998-11-11
6
197 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
create a gui in perl 3 70
custom annotations 9 29
Basic Java Case or If-Else statement... 3 43
object oriented programming comparison 5 52
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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 the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
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 …

919 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

16 Experts available now in Live!

Get 1:1 Help Now