Item listener for JList

Hi ,
I have a doubt regarding how to add an ItemListener for a JList in
java1.4.
I wud be thankful if someone helps me out with a sample program.
If it is not possible , wtz the reason .

Here's a very basic JList, with a ListSelectionListener
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
class JListDemo extends JFrame implements ListSelectionListener
  DefaultListModel listModel = new DefaultListModel();
  JList list = new JList(listModel);
  public JListDemo()
    super("JList Demo");
    setSize(300,400);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container window = getContentPane();
    list.addListSelectionListener(this);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    window.add(list);
    setLocation(400,300);
    setVisible(true);
    listModel.addElement("abc");
    listModel.addElement("Hello World");
    listModel.addElement("123");
  public void valueChanged(ListSelectionEvent lse)
    JOptionPane.showMessageDialog(null,list.getSelectedValue().toString());
  public static void main(String args[])
    new JListDemo();
}

Similar Messages

  • Action / Item listener for Choice Component

    Hi,
    I currently have a choice component on my GUI and have it populated. I now want to detect if an item has been selected at any point in time and handle an event. I have been able to do this for buttons with ease using an Actionevent, but I am having some difficulty acheiving this for a choice component. Upon researching I have found an itemevent can be used but there are no examples of how to use this.
    Can anyone suggest how this can be acheieved.
    Thanks!

    Go back and look at the API, they list the Listeners specific to the Choice Class and all Listeners that are inherited.
    An ItemListener is used by implementing ItemListener
    public class MyClass implements ItemListener{
    // your code
      public void itemStateChanged(ItemEvent e){
        //your event handling code here
      }If you are implementing the ItemListener in your Choice class, then when you add it:
    addItemListener(this);If your ItemListener is implmeented in another class then after instantiation of your ItemListener Ojbect:
    myChoiceObject.addItemListener(myItemListenerObject);

  • Double click for JList items selection

    I would like to select JList items only by double clicking on them. I can write a mouse listener for detecting double clicks by my own (and handle it afterwards), by please tell me how to turn the default behavior off (selecting items by clicking one time).
    Thanks in advance
    Marek

    I would like to select JList items only by double clicking on them. Well the standard is to select or highlight on a mouseClick or by using the arrow keys on the keyboard.
    Then once you have a selected item you can perform and Action on the item by double clicking or by using the enter key. Remember you should always be able to use either the keyboard or the mouse to perform any given function.
    This posting shows my solution for the above scenario:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=626866

  • Listen for menu item

    Is it possible to trigger something when a menu item it selected? I DON'T mean to create a menu item and the assign a script to it, but for example listen for a user clicking Search from the Help menu in Safari?
    If so, could someone point me in the right direction please.
    Thanks.

    +Short answer...+
    No. AppleScript does not work this way.

  • Item listener & combo boxes......please help me....thanks

    I did a applet that shows 4 jcombobox......the combo 2 is filling if the combo 1 is actioned, the combo3 is filling if the combo2 is actioned and the combo 4 have to be filled if the combo 3 is actioned.
    I did it...using item listener......it works fine....the first time....(in the console appears the lines that i specify using System.out.println).....but after...when i select any combo....i see in the console...that the itemlistener action is done several times......i don�t know why......do you have any idea or suggestion about it?............
    Thanks in advance...
    Mary
    This is the code:
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    import javax.swing.border.*;
    import javax.swing.event.*;
    import java.lang.*;
    import java.text.NumberFormat;
    import java.text.DecimalFormat;
    public class w3_a extends JApplet {
    Container contentPane;
    int i=10, j=20, k=30, l=40;
    private JComboBox jcb1;
    private JComboBox jcb2;
    private JComboBox jcb3;
    private JComboBox jcb4;
    private JTabbedPane jtp;
    private GriddedPanel jp1;
    private GriddedPanel jp2;
    public void init() {
    contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());
    add_JComboBoxes_GUI();
    add_JTabbedPanes_GUI();
    fill_combo1();
    void add_JComboBoxes_GUI() {
    jp1 = new GriddedPanel();
    jp1.setBorder( new EmptyBorder(new Insets(5, 5, 5, 5)) );
    jcb1 = new JComboBox();
    jcb2 = new JComboBox();
    jp1.add(jcb1);
    jp1.add(jcb2);
    contentPane.add(jp1, BorderLayout.NORTH);
    jcb1.addItemListener(new java.awt.event.ItemListener() {
    public void itemStateChanged(ItemEvent e) {
    System.out.println("Accion 1 - Element");
    fill_combo2();
    jcb2.addItemListener(new java.awt.event.ItemListener() {
    public void itemStateChanged(ItemEvent e) {
    System.out.println("Accion 2 - Element");
    fill_combo3();
    void add_JTabbedPanes_GUI() {
    jtp = new JTabbedPane();
    jtp.addTab("Datos Generales", new Panel_Data());
    contentPane.add(jtp);
    class Panel_Data extends JPanel {
    public Panel_Data() {
    // Primer panel de JTabbedPane de Datos Generales
    jp2 = new GriddedPanel();
    jp2.setBorder( new EmptyBorder(new Insets(5, 5, 5, 5)) );
    jcb3 = new JComboBox();
    jcb4 = new JComboBox();
    jp2.add(jcb3);
    jp2.add(jcb4);
    jtp.add(jp2);
    contentPane.add(jtp, BorderLayout.SOUTH);
    jcb3.addItemListener(new java.awt.event.ItemListener() {
    public void itemStateChanged(ItemEvent e) {
    System.out.println("Accion 3 - Element");
    fill_combo4();
    jcb4.addItemListener(new java.awt.event.ItemListener() {
    public void itemStateChanged(ItemEvent e) {
    System.out.println("Accion 4 - Element");
    void fill_combo1() {
    System.out.println("Start fill_combo1()");
    jcb1.removeAllItems();
    jcb1.addItem("combo1 " + (++i));
    jcb1.addItem("combo1 " + (++i));
    jcb1.addItem("combo1 " + (++i));
    System.out.println("End fill_combo1()");
    return;
    void fill_combo2() {
    System.out.println("Start fill_combo2()");
    jcb2.removeAllItems();
    jcb2.addItem("combo2 " + (++j));
    jcb2.addItem("combo2 " + (++j));
    jcb2.addItem("combo2 " + (++j));
    System.out.println("End fill_combo2()");
    return;
    void fill_combo3() {
    System.out.println("Start fill_combo3()");
    jcb3.removeAllItems();
    jcb3.addItem("combo3 " + (++k));
    jcb3.addItem("combo3 " + (++k));
    jcb3.addItem("combo3 " + (++k));
    System.out.println("End fill_combo3()");
    return;
    void fill_combo4() {
    System.out.println("Start fill_combo4()");
    jcb4.removeAllItems();
    jcb4.addItem("combo4 " + (++l));
    jcb4.addItem("combo4 " + (++l));
    jcb4.addItem("combo4 " + (++l));
    System.out.println("End fill_combo4()");
    return;

    Hi!!!
    Thanks by answer to me.....
    Yes ...i already understand why is happening in it.....
    I did modifications to my code to remove the listeners and after to add them....but no yet obtain my goal that the combo 2 is filling if the combo 1 is actioned, the combo3 is filling if the combo2 is actioned and the combo 4 have to be filled if the combo 3 is actioned.
    I think that at least should it to work for combo1 and combo2, because i don't know how to specify to add or remove the listener from the class de Panel_Data would be .....because i think that with:
    jcb3.removeItemListener(this);
    jcb3.addItemListener(this);
    jcb4.removeItemListener(this);
    jcb4.addItemListener(this);
    i am removing and adding the itemlistener from the main class w10_a (for combo3 and combo4)...... and not for the Panel_Data class.
    ie,
    jcb4.removeItemListener(
    //here is my doubt i don't know how to specify
    //to add or to remove the itemlistener from the
    //Panel_Data class for combo3 and combo4
    jcb4.addItemListener(
    //here is my doubt i don't know how to specify
    //to add or to remove the itemlistener from the
    //Panel_Data class for combo3 and combo4
    Well...i hope that you could help me please in give me some suggestions about it...
    Thanks in advance...
    Mary
    Here is my code modified:
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    import javax.swing.border.*;
    import javax.swing.event.*;
    import java.lang.*;
    import java.text.NumberFormat;
    import java.text.DecimalFormat;
    public class w10_a extends JApplet implements ItemListener{
    Container contentPane;
    int i=10, j=20, k=30, l=40;
    private JComboBox jcb1;
    private JComboBox jcb2;
    private JComboBox jcb3;
    private JComboBox jcb4;
    private JTabbedPane jtp;
    private GriddedPanel jp1;
    private GriddedPanel jp2;
    public void init() {
    contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());
    add_JComboBoxes_GUI();
    add_JTabbedPanes_GUI();
    fill_combo1();
    void add_JComboBoxes_GUI() {
    jp1 = new GriddedPanel();
    jp1.setBorder( new EmptyBorder(new Insets(5, 5, 5, 5)) );
    jcb1 = new JComboBox();
    jcb2 = new JComboBox();
    jp1.add(jcb1);
    jp1.add(jcb2);
    contentPane.add(jp1, BorderLayout.NORTH);
    jcb1.addItemListener(this);
    jcb2.addItemListener(this);
    void add_JTabbedPanes_GUI() {
    jtp = new JTabbedPane();
    jtp.addTab("Datos Generales", new Panel_Data());
    contentPane.add(jtp);
    class Panel_Data extends JPanel implements ItemListener {
    public Panel_Data() {
    // Primer panel de JTabbedPane de Datos Generales
    jp2 = new GriddedPanel();
    jp2.setBorder( new EmptyBorder(new Insets(5, 5, 5, 5)) );
    jcb3 = new JComboBox();
    jcb4 = new JComboBox();
    jp2.add(jcb3);
    jp2.add(jcb4);
    jtp.add(jp2);
    contentPane.add(jtp, BorderLayout.SOUTH);
    //Implementamos ActionListener para cada acci�n ejecutada
    jcb3.addItemListener(this);
    jcb4.addItemListener(this);
    public void itemStateChanged(ItemEvent e) {
    if ( e.getItemSelectable() == jcb3 ) {
    System.out.println("Accion 3 - Element");
    fill_combo4();
    if ( e.getItemSelectable() == jcb4 ) {
    System.out.println("Accion 4 - Element");
    public void itemStateChanged(ItemEvent e) {
    if ( e.getItemSelectable() == jcb1 ) {
    System.out.println("Accion 1 - Element");
    fill_combo2();
    if ( e.getItemSelectable() == jcb2 ) {
    System.out.println("Accion 2 - Element");
    fill_combo3();
    void fill_combo1() {
    System.out.println("Start fill_combo1()");
    jcb1.removeItemListener(this);
    jcb1.removeAllItems();
    jcb1.addItem("combo1 " + (++i));
    jcb1.addItem("combo1 " + (++i));
    jcb1.addItemListener(this);
    jcb1.addItem("combo1 " + (++i));
    System.out.println("End fill_combo1()");
    void fill_combo2() {
    System.out.println("Start fill_combo2()");
    jcb2.removeItemListener(this);
    jcb2.removeAllItems();
    jcb2.addItem("combo2 " + (++j));
    jcb2.addItem("combo2 " + (++j));
    jcb2.addItemListener(this);
    jcb2.addItem("combo2 " + (++j));
    System.out.println("End fill_combo2()");
    void fill_combo3() {
    System.out.println("Start fill_combo3()");
    jcb3.removeItemListener(this);
    jcb3.removeAllItems();
    jcb3.addItem("combo3 " + (++k));
    jcb3.addItem("combo3 " + (++k));
    jcb3.addItemListener(this);
    jcb3.addItem("combo3 " + (++k));
    System.out.println("End fill_combo3()");
    void fill_combo4() {
    System.out.println("Start fill_combo4()");
    jcb4.removeItemListener(this);
    jcb4.removeAllItems();
    jcb4.addItem("combo4 " + (++l));
    jcb4.addItem("combo4 " + (++l));
    jcb4.addItemListener(this);
    jcb4.addItem("combo4 " + (++l));
    System.out.println("End fill_combo4()");

  • How to  move items from one JList to other

    Can u pls help me out to implement this(I m using Netbeans 5.5):
    I want to move items from one JList to other thru a ADD button placed between JLists, I am able to add element on Right side JList but as soon as compiler encounter removeElementAt() it throws Array Index Out of Bound Exception
    and if I use
    removeElement() it removes all items from left side JList and returns value false.
    Pls have a look at this code:
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
    // TODO add your handling code here:
    Object selItem = jList1.getSelectedValue();
    int selIndex = jList1.getSelectedIndex();
    DefaultListModel model = new DefaultListModel();
    jList2.setModel(model);
    model.addElement(selItem);
    DefaultListModel modelr = new DefaultListModel();
    jList1.setModel(modelr);
    flag = modelr.removeElement(selItem);
    //modelr.removeElementAt(selIndex);
    System.out.println(flag);
    }

    hi Rodney_McKay,
    Thanks for valuable time but my problem is as it is, pls have a look what I have done and what more can b done in this direction.
    Here is the code:
    import javax.swing.DefaultListModel;
    import javax.swing.JList;
    public class twoList extends javax.swing.JFrame {
    /** Creates new form twoList */
    public twoList() {
    initComponents();
    //The code shown below is automatically generated and we can�t edit this code
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
    private void initComponents() {
    jScrollPane1 = new javax.swing.JScrollPane();
    jList1 = new javax.swing.JList();
    jButton1 = new javax.swing.JButton();
    jScrollPane2 = new javax.swing.JScrollPane();
    jList2 = new javax.swing.JList();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jList1.setModel(new javax.swing.AbstractListModel() {
    String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
    public int getSize() { return strings.length; }
    public Object getElementAt(int i) { return strings[i]; }
    jList1.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
    public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
    jList1ValueChanged(evt);
    jScrollPane1.setViewportView(jList1);
    jButton1.setText("ADD>>");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton1ActionPerformed(evt);
    jScrollPane2.setViewportView(jList2);
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(31, 31, 31)
    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addComponent(jButton1)
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addContainerGap(78, Short.MAX_VALUE))
    layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jScrollPane1, jScrollPane2});
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(62, 62, 62)
    .addComponent(jButton1))
    .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
    .addContainerGap(159, Short.MAX_VALUE))
    layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jScrollPane1, jScrollPane2});
    pack();
    }// </editor-fold>
    //automatic code ends here
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
    // TODO add your handling code here:
            jList1 = new JList(new DefaultListModel());
            jList2 = new JList(new DefaultListModel());
             Object selItem = jList1.getSelectedValue();
             System.out.println(selItem);
            ((DefaultListModel) jList1.getModel()).removeElement(selItem);
            ((DefaultListModel) jList2.getModel()).addElement(selItem);
    //Now trying with this code it is neither adding or removing and the value �null� is coming in �selItem� .It may be bcoz JList and Jlist are already instantiated in automatic code. So, I tried this:
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
    // TODO add your handling code here:
             Object selItem = jList1.getSelectedValue();
             System.out.println(selItem);
            ((DefaultListModel) jList1.getModel()).removeElement(selItem);
            ((DefaultListModel) jList2.getModel()).addElement(selItem);
    //Now with this as soon as I click on �jButton1�, it is throwing this error:
    Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: twoList$1 cannot be cast to javax.swing.DefaultListModel
            at twoList.jButton1ActionPerformed(twoList.java:105)
            at twoList.access$100(twoList.java:13)
            at twoList$3.actionPerformed(twoList.java:50)
            at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
            at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
            at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
            at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
            at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
            at java.awt.Component.processMouseEvent(Component.java:6038)
            at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
            at java.awt.Component.processEvent(Component.java:5803)
            at java.awt.Container.processEvent(Container.java:2058)
            at java.awt.Component.dispatchEventImpl(Component.java:4410)
            at java.awt.Container.dispatchEventImpl(Container.java:2116)
            at java.awt.Component.dispatchEvent(Component.java:4240)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
            at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
            at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
            at java.awt.Container.dispatchEventImpl(Container.java:2102)
            at java.awt.Window.dispatchEventImpl(Window.java:2429)
            at java.awt.Component.dispatchEvent(Component.java:4240)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

  • Getting multiple items from a Jlist

    hi i am trying to get selected items from a Jlist to print out
    but can only seem to get one item at a time using getSelectedValue()
    when i try and use getSelectedValues().toString(); i get
    the following print out [Ljava.lang.Object;@ed783f68 can anyone show me
    where i am going wrong and tell me why i get that print out
    cheers
    submitdetails.addActionListener(
                                                   new ActionListener() {
                                                           public void actionPerformed( ActionEvent e )
                                                      String data = privilegesList.getSelectedValue().toString();
                                                      Object data2 = privilegesList.getSelectedValues().toString();
                                                      System.out.println(data);
                                                      System.out.println(data2);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    The getSelectedValues(...) method returns and ARRAY of OBJECTS. You have to loop through the array to get each object separately:
    Object[] values = privilegesList.getSelectedValues();
    for (int j = 0; j < values.length; j++)
    System.out.println ( values[j].toString() );

  • Tab Item change for two panel group with 4 tabs each

    Hi
    All
    Will tab work for dynamic data loading in a panel group ?
    scenario .
    Panel group got 4 tabs . each tab contains grid view jsf component. these grid view will populate data once the Index page loads . each tab;s grid view will get data dynamically from backing bean with value objects .
    i am getting data for first tab . which is selected as true . but cannot change focus to other tabs. the functionality of tabchange event listener is not working. i checked the data for other tabs grid view. its coming correctly but cann;t see it in jsf page.
    tabs won;t work . is there any reason which stops working of tab , when we pass data dynamically to all grid views in 4 different tabs at a time.
    thanks in advance.
    Rambhapuri

    Data loading is happening , but cann;t change the tab , because tab item listener is not firing . when user clicks on other tab.
    regards
    rambhapuri

  • By default a item in a JList should selected

    Hi
    I need a item in the JList should be selected(not the first item) by default while I am creating a new instances for the JList.
    Note: I am rendering a button in the JList.
    with regrads
    senthil kumar

    You should be able to use either of the following methods of JList: setSelectedIndex(defaultIndex); or setSelectedValue(defaultObject, shouldScroll);Is one of these what you are looking for?

  • Disclosure Listener for PanelTabbed

    Hi All
    <<Jdeveloper 11.1.2.3.>>
    I have a paneltabbed component with 5 tabs (show detail item). My scenario is Every-time user clicks on a tab I need to perform same set of tasks (like refreshing the VO to check for new data).
    Only If the user selects Tab3 then the logic executed is different.
    What is the best of achieving this.
    Do I need to write a disclosure listener for every single tab or I can have a same disclosure listener for 4 tabs which does same action and one other disclosure listener for Tab3.
    Kindly guide me with the correct approach.
    regards,
    bnkr

    Hi,
    Here is the sample code with only one disclosure event for all tabs with condition inside to check which tag is disclosed:
    <af:panelTabbed id="pt1">
    <af:showDetailItem text="Tab 1" id="sdi1"
         disclosureListener="#{<Bean>.tabDisclosed}">
        <af:outputText value="Tab 1 Contents" id="ot1"/>
        <af:clientAttribute name="disclosedTab" value="Tab1"/>        
    </af:showDetailItem>
    <af:showDetailItem text="Tab 2" id="sdi2"
         disclosureListener="#{<Bean>.tabDisclosed}">
        <af:outputText value="Tab 2 Contents" id="ot2"/>
        <af:clientAttribute name="disclosedTab" value="Tab2"/>        
    </af:showDetailItem>              
    <af:showDetailItem text="Tab 3" id="sdi3"
         disclosureListener="#{<Bean>.tabDisclosed}">
        <af:outputText value="Tab 3 Contents" id="ot3"/>
        <af:clientAttribute name="disclosedTab" value="Tab3"/>        
    </af:showDetailItem>
    </af:panelTabbed>
    // Bean Code
        public void tabDisclosed(DisclosureEvent disclosureEvent){
            if (disclosureEvent.isExpanded() == true) {          
                if(disclosureEvent.getComponent().getAttributes().get("disclosedTab").equals("Tab3")){
                    //TODO Code when Tab 3 is disclosed              
                }else{
                    //TODO Code for other tabs
    Note that af:clientAttribute is set for each showDetailItem where we pass the value for disclosedTab attribute to identify which tab is disclosed
    Sireesha

  • Automatically scrolling to an item in a JList

    Hi all,
    i have several jlists with about 30 - 50 items and i would like to take the user directly to an item in the list as he enters characters that match a list item. Are there any existing interfaces with this behaviour? If not, has anyone written something similar to this?
    Thanks!

    Hi Linzie,
    the following code will automatically scroll the JList to the item entered in the JTextField:public class X extends JApplet {
         public void init() {
              final int CELL_HEIGHT = 15; //or figure out how to get it dynamically
              String[] items = new String[50]; //test items (format: item XX)
              for (int x = 0; x < items.length; x++) items[x] = "item " + x;
              final JList lst = new JList(items);
              final JScrollPane scroll = new JScrollPane(lst);
              Container c = getContentPane();
              c.setLayout(new BorderLayout());
              final JTextField text = new JTextField(20);
              text.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        String s = text.getText();
                        try {
                        int val = Integer.parseInt(s.substring(s.lastIndexOf(' ')+1, s.length()));
                        //this automatically scrolls to show
                        //the required cell of the JList
                        scroll.getVerticalScrollBar().setValue(val * CELL_HEIGHT);
                        lst.setSelectedIndex(val);
                        } catch(NumberFormatException ex) {
              c.add(text, BorderLayout.NORTH);
              c.add(scroll, BorderLayout.CENTER);
    }Cheers!

  • Item Listener problem

    I have an item listener on a checkbox within a table cell.
    At the time I get the SELECTED or DELECTED event, I invoke a method to update the gui based on the event.
    Well, to be precise, I retrieve data from the table model to get the status of each checkbox in the column and base a decision on whether any checkboxes in the column are checked. The problem is -- and it may be timing related -- is that sometimes the table model doesn't seem to reflect the new selected status of the checkbox I just clicked.
    Does anyone know the sequence of events when an item listener is hit -- does the table model get updated first, or perhaps the event happens and the model gets updated a bit later and I'm trying to do my evaluation too soon. If the latter case is true, does anyone have any thoughts on how to best workaround this situation? I've tried putting the evaluation code in a runnable with invokeLater and it doesn't help.
    Thanks for any thoughts on this.

    Thank you. I added a TableModelListener to listen for UPDATES to the cells in my column and fire the events for evaluation then and it works much better. Thanks for the clue.
    Isn't JTable's flexibility wonderful but mastering it a chore?! I'm getting there....

  • Selected item in a JList - Clear selection after mouse click

    Hello:
    I'm developing a Java GUI application which uses some JLists. I've seen that, when an item of the JList is selected and you click the mouse another time in the same selected item, the selection does not "disappear". Now, the only way I know to do this is tho press Control + click in the selected item.
    I would like that, when I click to the selected item of a list, the selection disappears.
    How can I solve that?
    Lots of thanks for your help.

    add a MouseListener to the list
    in mouseReleased (note: Released), get the selected index
    compare to previous selection - if the same, list.clearSelection()
    if you clear the selection, you'll need to reset the 'previous selection' variable

  • AP Line-Item Report for State Auditors

    Dear Members,
    I am preparing one Report named AP Line-Item Report for State Auditors and i need the following fields in my report.
    Check Number                PAYR-CHECT
    Voucher Number             BSEG-BELNR
    Check Date                     PAYR-ZALDT
    Voucher Date                     BKPF-BUDAT
    Vendor Number             LFA1-LIFNR
    Vendor Name                     ADRC-NAME1
    Vendor Street Address     ADRC-STREET
    Vendor City                     ADRC-CITY1
    Vendor State                     ADRC-REGIO
    Vendor Zip Code             ADRC-POST_CODE1
    General Ledger Acct No     BSEG-HKONT
    Purchase Order Number     BSEG-EBELN
    Tax Status Code             BSEG-MWSKZ
    Taxable Amount             BSEG-HWBAS
    Exempt Amount             BSEG-MWSTS
    Tax                                     BSEG-MWSTS
    Tax Accrued                     BSEG-MWSTS
    Total Invoice                      BSEG-DMBTR
    I am new to FI.So I request some one please let me know which datasources contain the above fields and which CUBE is best suited for this.
    Thanks in Advance for help and quick reply is much much appreciated.
    Best Regards
    RC

    0VENDOR_ATTR - Vendor Master Data Attributes
    0FI_AP_51 - Check Register Line Items
    0FI_AP_4 - Accounts Payable Line Items
    It should be noted, however, that this won't get you everything that you need, so you may have to create enhance one or more of these DataSources and create User Exit ABAP code to get the required data. Also, the 0FI_AP_51 DataSource isn't available if your source system isn't ECC6 EHP3 or higher. If your source system is less than that, you're going to have to create a generic DataSource for the data from the PAYR table.

  • Purchase items report for sales orders - very important

    Hi Folks,
    Could you please guide me on how to create a report of "items purchased" for a particular "sales order". if i am able to include various fields of items purchased, like....quantity, item description, vendor name, item price, etc., it will be very useful.
    This report is required for a client, who assembles machines in a "make to order" scenario, and most of the BOM child items are "purchase items".

    Hello Krishna,
    Few things to note:
    Is the PO created from the SO.  Is YES, then you could use the base document ref at the POR1 table.
    OR
    Are the BOM components defined with a default vendor in the Item Master and if YES are the components always purchased from the same vendor.
    I am trying to see how to establish the relationship of the items between the PO and SO.
    Please give me the details and I could guide you further
    Thanks
    Suda

Maybe you are looking for