Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: linking a popup-menu to each item of a JList

  1. #1
    Junior Member
    Join Date
    Sep 2023
    Location
    London
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default linking a popup-menu to each item of a JList

    I am new to GUIs development.
    I have to build a GUI mainly consisting of a JList, some JButtons and a JTextField.
    I use WindowBuilder as much as possible.
    My JList contains strings
    My problem is to associate an event to each item of my JList so that whenever an item is selected a popup menu appears wit the list of actions the can be applied to the item (string).
    I do not know if that is possible with a JList. If I right-click on the JList and choose "Add event handler" I cannot find a pre-defined event that can fire up a popup menu.
    If a popup menu cannot be associated to the items of a JList then I would appreciate some help with choosing another WindowBuilder component that can display a list of strings and supports a popup menu

    Thank you in advance

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: linking a popup-menu to each item of a JList

    Is this a question about how to write the code for a popup when an item in a JList is selected?
    I am not familiar with WindowBuilder.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2023
    Location
    London
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: linking a popup-menu to each item of a JList

    Quote Originally Posted by Norm View Post
    Is this a question about how to write the code for a popup when an item in a JList is selected?
    I am not familiar with WindowBuilder.
    By using WindowBuilder I have two environments to choose from, the "Source" and the "Design".
    In the "Design " workspace I see all the components I have added to my GUI laid out on a canvas (component JFrame).
    If I right-click on any component a menu pops up. One of its items is "Add event handler" which pops up another menu listing all the built-in events for the component.
    If I right-click on the JList --> Add event handler I cannot see any event that is triggered by the selection of an item (string) in the JList.

    Basically, any time an item is selected on the JList I would like a menu to pop up allowing for {"Delete Item", "Point Selection", "Add Item"}
    There should be actions associated to each one of these choices.
    "Delete Item" should remove the currently selected JList item (string) from the list
    "Add Item" should pop up a DialogBox that allows the user to enter a new item (string) inserted after/before the currebtly selected item
    "Point Selection" just memorizes the selected string that identifies one of the two ends of a segment.

    Some explanation.
    My GUI is aimed at helping a Maxillo-Facial surgoen to select points on a 3D scan of a patient's face. Each point is identified by a specific name (string). The doctor may want to select a segment, defined by two points, for specific measurements that are crucial to plan a surgery.

    Thank you for your help.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: linking a popup-menu to each item of a JList

    What have you tried so far? Please post your current code with some comments on what problems you are having.
    Be sure to wrap all posted code in code tags.

    Don't post a large program. Make a small special program for testing that can be posted here.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. [SOLVED] rtl (right to left) system tray popup menu items
    By cnmeysam in forum Java SE APIs
    Replies: 15
    Last Post: March 30th, 2021, 12:28 PM
  2. Popup menu problem
    By Ruthvik in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 19th, 2012, 07:37 AM
  3. Replies: 1
    Last Post: March 18th, 2012, 12:16 PM
  4. popup menu
    By antonio69 in forum AWT / Java Swing
    Replies: 1
    Last Post: May 20th, 2010, 04:24 AM
  5. Replies: 1
    Last Post: October 23rd, 2009, 03:17 PM

Tags for this Thread