Results 1 to 3 of 3
  1. #1
    tfunk92 is offline Member
    Join Date
    Oct 2013
    Posts
    5
    Rep Power
    0

    Default JList selection to open new window

    Hello,
    I have 2 JLists:
    Java Code:
                                 l1 = new String[]{"Customer Information", "Order Information", "Equiptment Information"}; 
    	
    		 setLayout(new FlowLayout());
    		 list1 = new JList(l1);
    		 list1.setFont (list1.getFont ().deriveFont (16.0f));
    		 list1.setFixedCellWidth(275);
    		 list1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    		 add(list1);
    And a JButton:
    Java Code:
    button2 = new JButton("Submit");
    I want to add an ActionListener to open a new window when a certain string is selected in the JList.
    Java Code:
    button2.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e)
             {
                 ///// Enter action here
            	 
             }
    });

    Cheers for any help.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,960
    Rep Power
    8

    Default Re: JList selection to open new window

    As always, the API is your best friend: JList (Java Platform SE 7 )

    JList has an addListSelectionListener() method that allows you to add a listener that detects list selection events.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    tfunk92 is offline Member
    Join Date
    Oct 2013
    Posts
    5
    Rep Power
    0

Similar Threads

  1. JList....open file from database...
    By paul78 in forum AWT / Swing
    Replies: 0
    Last Post: 08-07-2012, 08:01 PM
  2. Replies: 4
    Last Post: 01-10-2012, 01:05 PM
  3. Keeping a JOptionPane window open after selection.
    By Joshuak in forum New To Java
    Replies: 1
    Last Post: 12-10-2011, 08:11 AM
  4. Replies: 1
    Last Post: 07-25-2011, 10:24 AM
  5. Replies: 4
    Last Post: 02-07-2011, 08:43 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •