Solved

Items in a Choice

Posted on 1998-11-11
6
201 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 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
The viewer will learn how to implement Singleton Design Pattern in Java.

627 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