Results 1 to 2 of 2
  1. #1
    orushw is offline Member
    Join Date
    May 2011
    Posts
    8
    Rep Power
    0

    Default Problem with JList event.

    Hi,
    I created a calendar, that JList represents the days of the week, its look like that :
    Problem with JList event.-calendar.png
    I want to create event that every time i`ll click on one of the days (one of the JLists) i will add some appointment to this day.
    I have a problem to know which exactly list i clicked.
    This is the way i setup all my JLists :

    Java Code:
    JList list;
    for (int i=0; i<Days; i++)
    		{
    			calendar.set(Calendar.YEAR, Calendar.MONTH, i);
    			String TempStr[] = {Integer.toString(i+1) + "/" + Integer.toString(month) + "/" + Integer.toString(year)} ;
    			list = new JList<String>(TempStr);
    			list.addFocusListener(handler);
    			pane.add(list,c);
    		}

    How do i get to the context on every list?
    When i click on every list how can i know which exactly list i clicked?
    I have tried to you at the FocusEvent, but list.getSelectedValue() show me null.
    I hope that i was clear enough.
    Thanks for helpers,
    Or.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Problem with JList event.

    The FocusEvent object passed into the focusGained method will tell you which object set off the event. Call getSource() on the object, check to be sure that it's a JList, and then cast it to JList.

Similar Threads

  1. JList problem?
    By tom2zip in forum AWT / Swing
    Replies: 2
    Last Post: 01-12-2012, 07:12 AM
  2. Problem With jList
    By amitabh in forum NetBeans
    Replies: 3
    Last Post: 06-03-2010, 06:28 AM
  3. JTabbedPane & JList Event Handling
    By MuslimCoder in forum New To Java
    Replies: 2
    Last Post: 10-05-2009, 05:44 AM
  4. JList and JButton event handler not working
    By H3rtaherta in forum AWT / Swing
    Replies: 3
    Last Post: 11-22-2008, 12:00 AM
  5. JList problem
    By zizou147 in forum Advanced Java
    Replies: 1
    Last Post: 04-17-2008, 08:50 AM

Posting Permissions

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