JList selection is listened twice

Hi
How to make JList selection listener to catch selection events for only one mouse click (mouse pressed or mouse released)

Hi,
you are right!
first time e.getValueIsAdjusting() is true second time
it is false. It does not corrspond to mousePressed or mouseReleased. I think the first is an item loosing selection and the second is another item getting selection (just a guess).
Phil

Similar Messages

  • Selecting an item twice in JList

    Hy,
    I have create a JList with some animal's name in it. When I click on one of the animal's
    name for the FIRST time, it appears in a JTextArea.
    What I want is that when I click on that same name consecutively, it appears again in that
    JTextArea. Can anyone please send me the code for doing that. Its very urgent.
    Here are my code:
    import javax.swing.*;
    import javax.swing.text.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    public class PropertyWindow extends JFrame implements ListSelectionListener, ActionListener {
         private JList list;
         private JScrollPane scrollTextArea;
         private JTextArea textArea;
         private String text;
         private Vector imageNames;
         private JLabel picture;
         private DefaultListModel listModel;
         public PropertyWindow () {
              super("Property Window");
              //create a text area
              textArea = new JTextArea();
              textArea.setFont(new Font("Arial", Font.PLAIN, 16));
              textArea.setLineWrap(true);
              textArea.setWrapStyleWord(true);
              //create a scrollpane and add it to the text area
              scrollTextArea = new JScrollPane(textArea);
              scrollTextArea.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
              scrollTextArea.setPreferredSize(new Dimension(200,35));
              //create a list of button and add it to the JPanel
              JButton addButton = new JButton("+");
              JButton subtractButton = new JButton("-");
              JButton multiplyButton = new JButton("x");
              JButton divideButton = new JButton("/");
              JButton assignButton = new JButton("=");
              JButton equalButton = new JButton("= =");
              JButton greaterButton = new JButton(">");
              JButton G_EqualButton = new JButton("> =");
              JButton lessButton = new JButton("<");
              JButton L_EqualButton = new JButton("< =");
              JButton notEqualButton = new JButton("! =");
              JButton oneButton = new JButton("1");
              JButton twoButton = new JButton("2");
              JButton threeButton = new JButton("3");
              JButton fourButton = new JButton("4");
              JButton fiveButton = new JButton("5");
              JButton sixButton = new JButton("6");
              JButton sevenButton = new JButton("7");
              JButton eightButton = new JButton("8");
              JButton nineButton = new JButton("9");
              JButton zeroButton = new JButton("0");
              addButton.setActionCommand ("+");
              subtractButton.setActionCommand("-");
              multiplyButton.setActionCommand("x");
              divideButton.setActionCommand ("/");
              assignButton.setActionCommand ("=");
              equalButton.setActionCommand ("= =");
              greaterButton.setActionCommand (">");
              G_EqualButton.setActionCommand ("> =");
              lessButton.setActionCommand ("<");
              L_EqualButton.setActionCommand ("< =");
              notEqualButton.setActionCommand("! =");
              oneButton.setActionCommand ("1");
              twoButton.setActionCommand ("2");
              threeButton.setActionCommand ("3");
              fourButton.setActionCommand ("4");
              fiveButton.setActionCommand ("5");
              sixButton.setActionCommand ("6");
              sevenButton.setActionCommand ("7");
              eightButton.setActionCommand ("8");
              nineButton.setActionCommand ("9");
              zeroButton.setActionCommand ("0");
              JPanel buttonPane = new JPanel();
              buttonPane.setBorder(
                                            BorderFactory.createCompoundBorder(
                                       BorderFactory.createCompoundBorder(
                                  BorderFactory.createTitledBorder("Arithmetic/Logical Operations"),
                                  BorderFactory.createEmptyBorder(5,5,5,5)),
                                       buttonPane.getBorder()));
              buttonPane.setLayout(new GridLayout (3,7));
              buttonPane.add(addButton);
              buttonPane.add(subtractButton);
              buttonPane.add(multiplyButton);
              buttonPane.add(divideButton);
              buttonPane.add(assignButton);
              buttonPane.add(equalButton);
              buttonPane.add(greaterButton);
              buttonPane.add(G_EqualButton);
              buttonPane.add(lessButton);
              buttonPane.add(L_EqualButton);
              buttonPane.add(notEqualButton);
              buttonPane.add(oneButton);
              buttonPane.add(twoButton);
              buttonPane.add(threeButton);
              buttonPane.add(fourButton);
              buttonPane.add(fiveButton);
              buttonPane.add(sixButton);
              buttonPane.add(sevenButton);
              buttonPane.add(eightButton);
              buttonPane.add(nineButton);
              buttonPane.add(zeroButton);
              addButton.addActionListener(this);
              subtractButton.addActionListener(this);
              multiplyButton.addActionListener(this);
              divideButton.addActionListener(this);
              assignButton.addActionListener(this);
              equalButton.addActionListener(this);
              greaterButton.addActionListener(this);
              G_EqualButton.addActionListener(this);
              lessButton.addActionListener(this);
              L_EqualButton.addActionListener(this);
              notEqualButton.addActionListener(this);
              oneButton.addActionListener(this);
              twoButton.addActionListener(this);
              threeButton.addActionListener(this);
              fourButton.addActionListener(this);
              fiveButton.addActionListener(this);
              sixButton.addActionListener(this);
              sevenButton.addActionListener(this);
              eightButton.addActionListener(this);
              nineButton.addActionListener(this);
              zeroButton.addActionListener(this);
              //create the 'ok' and 'cancel' button
              JButton okButton = new JButton("Ok");
              JButton cancelButton = new JButton("Cancel");
              okButton.setActionCommand("Ok");
              okButton.addActionListener(this);
              cancelButton.setActionCommand("Cancel");
              cancelButton.addActionListener(this);
              JPanel controlPane = new JPanel();
              controlPane.setLayout(new FlowLayout());
              controlPane.add(okButton);
              controlPane.add(cancelButton);
              //create a Jlist where to insert variables
              listModel = new DefaultListModel();
    listModel.addElement("dog");
    listModel.addElement("cat");
    listModel.addElement("rat");
    listModel.addElement("rabbit");
    listModel.addElement("cow");
              list = new JList(listModel);
              list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
              //list.setSelectedIndex(0);
              list.addListSelectionListener(this);
              JScrollPane scrollList = new JScrollPane(list);
              scrollList.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
              scrollList.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    scrollList.setPreferredSize(new Dimension(200,300));
              scrollList.setBorder(
                                            BorderFactory.createCompoundBorder(
                                       BorderFactory.createCompoundBorder(
                        BorderFactory.createTitledBorder("Variables"),
                        BorderFactory.createEmptyBorder(5,5,5,5)),
                                       scrollList.getBorder()));
              //create a pane and put the scroll list and ok/cancel button in it
              JPanel rightPane = new JPanel();
              BoxLayout rightBox = new BoxLayout(rightPane, BoxLayout.Y_AXIS);
              rightPane.setLayout(rightBox);
              rightPane.add(scrollList);
              rightPane.add(controlPane);
              //create a pane and put the scroll text area and arithmetic button in it
              JPanel leftPane = new JPanel();
              BoxLayout leftBox = new BoxLayout(leftPane, BoxLayout.Y_AXIS);
              leftPane.setLayout(leftBox);
              leftPane.add(scrollTextArea);
              leftPane.add(buttonPane);
              //add both pane to the container
              JPanel contentPane = new JPanel();
              BoxLayout box = new BoxLayout(contentPane, BoxLayout.X_AXIS);
              contentPane.setLayout(box);
              contentPane.add(leftPane);
              contentPane.add(rightPane);
    setContentPane(contentPane);
         public void valueChanged(ListSelectionEvent e) {
         if (e.getValueIsAdjusting() == false) {
         if (list.getSelectedIndex() == -1) {
              //No selection, disable fire button.
         else {
              //Selection, update text field.
         String name = list.getSelectedValue().toString();
         textArea.append(" " + name + " ");
         public void actionPerformed(ActionEvent e) {
              String cmd = e.getActionCommand();
              if (cmd.equals("Ok")) {
                   // save current textarea
                   text = textArea.getText();
                   System.out.println(text);
                   dispose();
                   setVisible(false);
              if (cmd.equals("Cancel")) {
                   dispose();
                   setVisible(false);
              if (cmd.equals("+")) {
                   textArea.append(" + ");
              if (cmd.equals("-")) {
                   textArea.append(" - ");
              if (cmd.equals("x")) {
                   textArea.append(" x ");
              if (cmd.equals("/")) {
                   textArea.append(" / ");
              if (cmd.equals("=")) {
                   textArea.append(" = ");
              if (cmd.equals("= =")) {
                   textArea.append(" == ");
              if (cmd.equals(">")) {
                   textArea.append(" > ");
              if (cmd.equals("> =")) {
                   textArea.append(" >= ");
              if (cmd.equals("<")) {
                   textArea.append(" < ");
              if (cmd.equals("< =")) {
                   textArea.append(" <= ");
              if (cmd.equals("! =")) {
                   textArea.append(" != ");
              if (cmd.equals("1")) {
                   textArea.append("1");
              if (cmd.equals("2")) {
                   textArea.append("2");
              if (cmd.equals("3")) {
                   textArea.append("3");
              if (cmd.equals("4")) {
                   textArea.append("4");
              if (cmd.equals("5")) {
                   textArea.append("5");
              if (cmd.equals("6")) {
                   textArea.append("6");
              if (cmd.equals("7")) {
                   textArea.append("7");
              if (cmd.equals("8")) {
                   textArea.append("8");
              if (cmd.equals("9")) {
                   textArea.append("9");
              if (cmd.equals("0")) {
                   textArea.append("0");
         public static void main(String args []) {
         JFrame frame = new PropertyWindow();
         frame.addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
         System.exit(0);
         frame.pack();
         frame.setVisible(true);
         frame.setResizable(false);
    }

    If the whole point of the JList is to display the information in the JTextArea and you don't mind losing the selection in the JList I have a solution for you (just had something similar come up).
    Add the following lines in the public void valueChanged(ListSelectionEvent e) method:
    listModel = list.getModel();
    list.setModel(listModel);
    This causes the particular animal in the JList to be un-selected and with each subsequent clicks on that JList selection a new ListSelectionEvent will fire and the text will keep appending.
    This gives the effect of a JList just being a bunch of buttons that can be clicked on all you want.

  • JList selection problems

    I'm having problems with JList selection - it's really wierd.
    I have a Jlist and on different selections I want to do stuff - well, I do see the GUI line get highlighted but everytime my ListSelectionListener is called the selected index stays 0.
    also, it always calls the ListSelectionListener twice for every selection I make.
    here's how my code looks:
    (typesList is my JList)
    typesList.setSelectedIndex(0);
    typesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    typesList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
          public void valueChanged(ListSelectionEvent e) {       
            int newSelection = typesList.getSelectedIndex(); //this returns always 0!        ...
          }

    Look at the line getValueIsAdjusting... (only one selection is processed. And, this code works and provides proper index.
        * Method to load all Tables from Database user
        public void loadTables() {
            // run Database request
            tableListModel = getListModelData("select object_name from user_objects where object_type = 'TABLE'");
            // now plug List with Model
            tableList = new JList(tableListModel);
            tableList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            tableList.setSelectedIndex(0);
            //tableList.addListSelectionListener(this);
            tableList.addListSelectionListener(
                new ListSelectionListener() {
                    public void valueChanged( ListSelectionEvent e )
                        if(e.getValueIsAdjusting()) return;
                        String tablename = tableList.getSelectedValue().toString();
                        showColumnData(tablename);
                        displayAllTableData(tablename); //intensive (reworking)
            jScrollPane1.add(tableList);
            jScrollPane1.setViewportView(tableList);
            showColumnData(tableList.getSelectedValue().toString());
        }PiratePete
    http://www.piratepetesoftware.com

  • How to 'veto' a jList selection change

    Hi All,
    I have a JList which I'm using as a record selector - so whenever my user selects an item on the list, the associated record is loaded up into the other controls on this form for editing. If the user edits any of the data items, I want to ask whether to save changes or not if another item is selected from the JList. So, I've added code in my 'selection changed' function to check for changes and show a 'yes/no/cancel' JOptionPane. The code for my 'yes' and 'no' respones work fine - either save the changes or not, then show the next record. My problem is handling if a user clicks cancel...
    If the user selects 'Cancel', I dont want any of my "show new record" code to execute (this is easy, I can just 'return' out of the function) but also I don't want the JList selection to change. I've tried calling setSelectedIndex() back to the originally selected item, but this in turn triggers my 'selection changed' function to be called again, which causes the user to be asked twice whether they want to save changes!
    So, what I'm after is a kind of beforeSelectionChanged event, which allows the possibility of denying the selection change - but it doesn't look like this exists! I vaguely remember another language (possibly C++/MFC) having this - the user's action could be ignored depending on the return value of the function. Can anyone offer a way of achieving this in Java?
    (It's been a while since I last touched Java, and I'm a complete n00b with Swing. Using NetBeans as my IDE.)
    Thanks in advance for any suggestions!
    Andy

    The way I do it, is to implement a VetoableSelectionModel similar to a bean with a vetoable property: on selection change it queries registered VetoableChangeListeners if they don't object and backs out if one of them barks.
    HTH
    Jeanette

  • Can you add audio tracks as selectable menu items on a dvd? I shot a wedding where the church had its own set up to record audio. I'm trying to make those songs performed by the artists available for viewers of the dvd to select for listening.?

    I'm trying to make audio (MP3) tracks available for viewers of this Wedding dvd to select for listening. Is this possible in iDVD?

    You will need to create a slide show for each of those songs with a minimum of 1 photo per slideshow and add the song to the slideshow audio bin. Set the audio to Fit to Music.
    In your top/main menu add a submenu for the list of songs.
    Add a slideshow for each song with the "+" button at the bottom:
    Select the link in the menu and rename it for the song used in the slideshow.  You can create a slide image for each song with the song name, composer, singer, etc. on the image to be used for the slideshow  An image editor or Pages can be used for that and then convert to a jpeg file for use in iDVD.
    The song/playlist menu could look like this depending on the theme you choose:
    OT

  • JList Selection Listener

    How can i add a listener to a JList so that it runs a method when the selection has changed? I have already looked at the tutorial but it seems to be over complicated for what i need.
    I have tried:
    addFinanceList.addListSelectionListener(new ListSelectionListener()
    public void valueChanged(ListSelectionEvent event)
    CP.getFinance().loadFinance((String)addFinanceList.getSelectedValue());
    updateDisplay();
    But this never executes.
    Can anyone help?

    Sure it never executes? If you select items in the
    list, what you've written looks correct. I'd shove a
    println or log message in the valueChanged method to
    see what's happening.Tried that...still nothing happens!

  • JList item selected is displayed twice. Please Assist

    Folks,
    I have this strange behaviour when I select an item from the JList.
    When I select the an item, it gets displayed twice.
    Can anyone tell me why this is being displayed twice?
    I am also checking the Java Sun Swing tutorials site..but no luck as yet.
    Attached is a short class.
    If you click on Black or Blue etc ,it gets displayed twice...
    public class JListDemo extends JFrame{
    private JList colorList;
    private Container c;
    private String colorNames[] = {"Black", "Blue","Red","Green","Yellow"};
    public JListDemo() {
    super("JList Demo");
    c = getContentPane();
    c.setLayout(new FlowLayout());
    /** Create a List */
    colorList = new JList(colorNames);
    colorList.setVisibleRowCount(3);
    colorList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    c.add(new JScrollPane(colorList));
    //** Set up Event Handler.
    colorList.addListSelectionListener(
    new ListSelectionListener() {
    public void valueChanged(ListSelectionEvent e)
    System.out.println(colorList.getSelectedValue());
    setSize(1000,550);
    show();
    public static void main(String[] args) {
    JListDemo JListDemo1 = new JListDemo();
    }

    in your ListSelectionListener you must check if the event is one of multiple change events. In your case you get one event when the mouse first selects an item and possible more when you move the cursor over the other entries. If you are only interested in the final selection check if e.getValueIsAdjusting() is false.
    // not interested in events if they are not final
    if (e.getValueIsAdjusting())
        return;
    // do what ever you want
    System.out.println(colorList.getSelectedValue());
    ...Hope this helps!

  • How do I get my JList selection to Display after changing

    Granted there are probably 1,000,000,000 ways to write this code. The intent is to have a list of items that are assigned into catagories and when an item is selected the catagories that the item are in are highlighted in the list. This part works OK, as I change items the catagories change to reflect the current item catagories. I have two buttons to add catagories to items and remove catagories from items. The catagory to add is selected from a JCombo drop down list and then the user clicks the addcat button to add the catagory to the item.
    My problem is that the catagories in the JList (that also reside in a JScrollPane) do not show as selected after the list is updated. If I click the addcat button twice then the new catagory is highlighted. I thought that the suggestion in other forum messages to add revalidate and repaint would work so I tried that both at the list and the scrollpane level with no effect.
    -------------- Button Listener code --------------------
    addcat.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    // get the curent catagory from the JCombo..
         String selectedcat = (String) fullcatlist.getSelectedItem();
    // get the curent Item from the JCombo..
         String selecteditem = (String) itemlist.getSelectedItem();
    // add item to catagory
         items.addItemCatagory(selecteditem,selectedcat);
    // debug
         product.setText(selectedcat +"::"+selecteditem);          
         int cnt = 0;
    // get a list of all catagories for this item
         String[] tgtList = catagories.getItemCatagories(selecteditem);
         // debug
         product.setText(selectedcat);          
    // get the JList list
         final ListModel lm = catlist.getModel();
    // get the list size
         int lsize = lm.getSize();
         String st ="";
         for (int j = 0; j < lsize;j++) {
    // get jth element of the list
         st = (String)lm.getElementAt(j);
    // compare it to the selected catagories list in if a match
    // set the index into the selected index array
         for (int k=0;k<tgtList.length;k++) {
         if ( st.compareTo(tgtList[k]) == 0 )
         lst[cnt++]=j;          
    //set up the selections
         int[] ilst = new int[cnt];
         for (int k = 0; k<cnt;k++)
         ilst[k] = lst[k];
    // enable teh selected indice
         catlist.setSelectedIndices(ilst);
    // paint the frame
         scrollPane.revalidate();
         scrollPane.repaint();
    --------------------- end code -----------------

    This might sound sarcastic, but it's not:
    I have no clue how to fix your code, but if your bored and want to try something, try copy-and-pasting that section right afterwards. You'd probably need to change some variables, but, again, I have no clue. This is all just a wild guess. Sorry I couldn't help you any more.

  • JList Selection Event

    Hi, here is one problem i am facing.
    i have a JList and i am using Selection Listener for that. Now selection listener has only one even in it valueChanged. which is only fired when some value is changed in the JList, i.e., if we select the same value twice consecutively, this event is fired only once only when that value is selscted for the first time. but i want this even to be fired every time i select a value (even twice or thrice consecutively). can u plz help me or tell me any other event?
    -Ashish

    problem is I cannot recieve which chat room is selected (let's say I don't know how to get it :) )Sorry I didn't get the humor :-( So let's try a dry answer:
    Try "jlist.getSelectedValue()" and cast it to the common supertype of all objects stuffed in the JList's model (I assume they are String or ChatRoom objects).
    and also selected index is appended twice when I click on any of them ? Can it be done by double click ?You receive two events (deselection of current item - selection of new item). You can distinguish them with event.getValueIsAdjusting().
    Brgds.

  • JList Selection

    Hello everyone,
    first of all, excuse me for my poor english.
    I have a JList contaning nearly 200 items and I would like the maximum selectable item count to be 5.
    I thought a good way to do that could be to add a listener to the list data and each time an event occurs on the list data run the getSelectedIndexes() method. Then if the result length is more than 5 the event could be canceled.
    But, I am not sure it's the best way to do that and most of all I don't know how to cancel and event.
    Could some help me please. Thank yopu very much.

    Thank you for your answer because the code you gave me is the one I use, so now I'm sure it's the good way to proceed.
    My problem is that I don't know what to do in remplacement of the comment. That's to say I don't know how to unselect the box just selected by the user witch is not necessary the one with the higher index.
    In this case: user selects items with following indexes : 1, 7, 8, 125, 130 and then a 6th: 34. The min index will be 1, the max index wille be 130, but how can I know that the last selected index is 34.
    That's why I wanted to "cancel" the event; in order to unselect the last selected item.
    Thank you

  • JList Selected Value

    Hey all,
    I have been trying to write a Listener for a JList. I simply need to get the selected value and make it display on a JLabel.
    My problem is that I cannot seem to find what I need.
    How do I use the command "getSelectedIndex" when the item is clicked in a JList? I made a listener that outputs to the terminal when its clicked, it appears to be working.
    Here is the code:
       class SharedListSelectionHandler implements ListSelectionListener {
            public void valueChanged(ListSelectionEvent e) {
               System.out.println("Hello World");
        }

    Hey,
    Try this,
       class SharedListSelectionHandler implements ListSelectionListener {
         public void valueChanged(ListSelectionEvent e) {
              JList list = (JList) e.getSource();
              if (e.getValueIsAdjusting() == false) {
                   if (list.getSelectedIndex() == -1) {
                        System.out.println("Nothing selected.");
                   } else {
                        // THIS WAY/////////
                        String text = (String) list.getSelectedValue();
                        // OR THIS WAY/////
                        ListModel model = list.getModel();
                        text = (String) model.getElementAt(e.getFirstIndex());                    
                        System.out.println(text);
        } You need to look at the ListModel really to get a better understanding of the MVC approach. Also - If you haven't used String objects you will get a ClassCastException. I'm just assuming you have.

  • New JList loses the listener.

    I have a gui, which I need to update with new lists depending on the selection of the user. The list is being listened to by ListSelectionListener. After I new the JList (for updating with new values). The listener doesn't recognize the source anymore. Any clues as to why?
    Code snippet below. getAttrs() function is called
    based on some selection by the user. So if the selection changes, this fn will be called.
    getAttrs() {
    Vector listVec = new Vector();
    listVec.add(...
    listVec.add(...
    attrList = new JList(listVec);
    attrList.addListSelectionListener(new ListSelectionListener(){
    public void valueChanged(ListSelectionEvent ev) {
    Object src = ev.getSource();
    System.out.println("src:"+src.toString());
    if ( src == attrList ) {
    if (!ev.getValueIsAdjusting()) {
    Object[] selectedObjs = ((JList)src).getSelectedValues();
    if (selectedObjs.length > 1) {
    System.out.println("multi objects");
    else {
    String attrName = (String)selectedObjs[0];
    System.out.println("attr"+attrName);
    setDetailValues(attrName);
    else {
    System.out.println("value is still changing");
    else {
    System.out.println("not attrList");
    What happens is that first time, it works oks and recognozes the src. next time (when the user selection changes and this function is called again) it says "not attrList" meaning it doesnt' reconize the src.

    Where do you add the JList? It looks like you added the first JList to a Container. The next time through this method, you are changing only the attrList reference, not the original and different JList object that you added. I think the original listener is what's being called, and since the old JList is calling the listener, the source is not the same as the attrList JList.
    Instead of making a new JList, you should update the original JList that you added.

  • JList selection issue

    I am stuck again, this time with the behaviour of a JList!
    This is what I am trying to do: I want a selection list, in which any combination of items can be selected. And I want the deselection of a selected item to happen the same way the selection happens- when the user points on the item and clicks the mouse button. It seems that this behaviour is not predefined and multiple selection is only available through use of a key.
    Any ideas how to do this? Easy ways to do it are particularly welcome!
    Thanks a lot!

    If I really wanted this kind of behavior (simple mouse click to select/deselect) I would possibly use an array of JCheckBoxes in a JPanel (in a JScrollPane, if needed) in a GridLayout with one column (or maybe a vertical BoxLayout). To rephrase what E'hic said, introducing non-standard behavior can lead to a non-intuitive user experience.
    Another way could be to use a two column JTable with one Booolean and one String column. Or even only one column holding a custom class containing a boolean and String field, with a custom renderer and editor to show a JCheckBox with appropriate text set.
    Yes, a JList can be tweaked to do what you want, and I'm sure I've seen a solution for this here -- search the forum and you might find something. It's not what I would do, though.
    db

  • Php mysql select query executes twice

    I have a select query running in a page that returns an image array and when it executes Firefox is returning the results twice. I have tested it in IE, and it runs fine. Just wondering if anyone would know why this is happening. I have searched many php and mySQL blogs and forums for an answer but have found nothing. This is my last hope. I also tested the query in phpMyAdmin and it executes fine with no errors. Thank you in advance for any ideas or help.

    A good place to ask questions and advice about web development is at the mozillaZine Web Development/Standards Evangelism forum.<br />
    The helpers at that forum are more knowledgeable about web development issues.<br />
    You need to register at the mozillaZine forum site in order to post at that forum.<br />
    See http://forums.mozillazine.org/viewforum.php?f=25

  • Selecting same column twice makes query slow

    Hello,
    Has anybody any idea why following statement is slow when selecting the
    DATA_TYPE column twice?
    SELECT S.OWNER,
    S.SYNONYM_NAME,
    UCOL.COLUMN_NAME,
    UCOL.DATA_TYPE,
    UCOL.DATA_TYPE,
    UCOL.DATA_LENGTH,
    COLUMN_ID
    FROM ALL_SYNONYMS S,
    ALL_TAB_COLUMNS UCOL
    WHERE S.TABLE_OWNER = UCOL.OWNER
    AND S.TABLE_NAME = UCOL.TABLE_NAME
    and S.owner = 'REPORTING_TEST'
    and S.SYNONYM_NAME = 'OV_COMMERCIAL_ENTITY_JN'
    Replace the owner and table name with one of your own.
    If you take one of the DATA_TYPE's out the select is much faster.
    Why, I hear you ask, do you select the same column twice?
    Well, it's not me. It's BusinessObjects when it does a structure refresh it
    produces a statement similar to the one above except that one of the
    DATA_TYPE's is a SUBSTR + DECODE (however they in themselves
    have virtually no impact on the statement). I just find it weird that repeating
    a column twice can have such a dramatic impact on performance.
    I'm not a tuning expert and have looked at EXPLAIN PLAN outputs but can't
    make head nor tail of them.
    Thanks,
    Ruud

    Yes it's true that Oracle caches data but I did run both statements several times within the same session. Run statement 1, run statement 2, add 2nd column and run again, take column away and run again, etc. Always the results were the same. The query with duplicate columns ran in seconds, the one without in milliseconds.
    If it tells you anything, below both explain plans. The main difference that I noticed is the full table scan on USER$ for the first query. The second one (although a more elaborate execution plan) seems to use indexes more.
    Don't spend too much time on this. I've found a workaround where I create temporary tables for ALL_SYNONYMS and ALL_TAB_COLUMNS and re-direct the public synonyms to point at those. After I've done what I wanted to do with BusinessObjects, I restore the original public synonyms. Next thing I'll try is rebuilding my database from scratch and see if the problem is still there.
    Apologies if the listings come out in variable font (how do you paste fixed font?).
    === SQL1 ====================================================
    EXPLAIN PLAN FOR
    SELECT UCOL.COLUMN_NAME,
    UCOL.DATA_TYPE,
    UCOL.DATA_TYPE
    FROM ALL_SYNONYMS S,
    ALL_TAB_COLUMNS UCOL
    WHERE S.TABLE_OWNER = UCOL.OWNER
    AND S.TABLE_NAME = UCOL.TABLE_NAME
    AND S.owner = 'REPORTING_TEST'
    AND S.SYNONYM_NAME = 'OV_COMMERCIAL_ENTITY_JN'
    Explained.
    Elapsed: 00:00:00.04
    SQL> @E:\Oracle\Product\10.2.0\db_1\RDBMS\ADMIN\utlxpls.sql
    Plan hash value: 1692851197
    | Id | Operation | Name |
    | 0 | SELECT STATEMENT | |
    | 1 | NESTED LOOPS | |
    | 2 | NESTED LOOPS | |
    | 3 | NESTED LOOPS | |
    | 4 | TABLE ACCESS BY INDEX ROWID | USER$ |
    |* 5 | INDEX UNIQUE SCAN | I_USER1 |
    | 6 | VIEW | ALL_TAB_COLUMNS |
    |* 7 | FILTER | |
    | 8 | NESTED LOOPS OUTER | |
    | 9 | NESTED LOOPS OUTER | |
    | 10 | NESTED LOOPS OUTER | |
    | 11 | NESTED LOOPS OUTER | |
    | 12 | NESTED LOOPS | |
    | 13 | NESTED LOOPS | |
    | 14 | TABLE ACCESS FULL | USER$ |
    | 15 | TABLE ACCESS BY INDEX ROWID| OBJ$ |
    |* 16 | INDEX RANGE SCAN | I_OBJ2 |
    |* 17 | TABLE ACCESS CLUSTER | COL$ |
    |* 18 | INDEX UNIQUE SCAN | I_OBJ# |
    |* 19 | TABLE ACCESS CLUSTER | COLTYPE$ |
    |* 20 | INDEX RANGE SCAN | I_HH_OBJ#_INTCOL# |
    |* 21 | TABLE ACCESS BY INDEX ROWID | OBJ$ |
    |* 22 | INDEX RANGE SCAN | I_OBJ3 |
    | 23 | TABLE ACCESS CLUSTER | USER$ |
    |* 24 | INDEX UNIQUE SCAN | I_USER# |
    |* 25 | TABLE ACCESS CLUSTER | TAB$ |
    |* 26 | INDEX UNIQUE SCAN | I_OBJ# |
    | 27 | NESTED LOOPS | |
    | 28 | FIXED TABLE FULL | X$KZSRO |
    |* 29 | INDEX RANGE SCAN | I_OBJAUTH2 |
    |* 30 | FIXED TABLE FULL | X$KZSPR |
    |* 31 | TABLE ACCESS BY INDEX ROWID | OBJ$ |
    |* 32 | INDEX RANGE SCAN | I_OBJ2 |
    |* 33 | TABLE ACCESS BY INDEX ROWID | SYN$ |
    |* 34 | INDEX UNIQUE SCAN | I_SYN1 |
    Predicate Information (identified by operation id):
    5 - access("U"."NAME"='REPORTING_TEST')
    7 - filter(("O"."TYPE#"=3 OR "O"."TYPE#"=4 OR "O"."TYPE#"=2 AND NOT
    EXISTS (SELECT 0 FROM "SYS"."TAB$" "T" WHERE "T"."OBJ#"=:B1 AND
    (BITAND("T"."PROPERTY",512)=512 OR BITAND("T"."PROPERTY",8192)=8192)))
    AND ("O"."OWNER#"=USERENV('SCHEMAID') OR EXISTS (SELECT 0 FROM
    "SYS"."OBJAUTH$" "OBJAUTH$",SYS."X$KZSRO" "X$KZSRO" WHERE "OBJ#"=:B2
    AND "GRANTEE#"="KZSROROL") OR EXISTS (SELECT 0 FROM SYS."X$KZSPR"
    "X$KZSPR" WHERE "INST_ID"=USERENV('INSTANCE') AND ((-"KZSPRPRV")=(-45)
    OR (-"KZSPRPRV")=(-47) OR (-"KZSPRPRV")=(-48) OR (-"KZSPRPRV")=(-49) OR
    (-"KZSPRPRV")=(-50)))))
    16 - access("O"."OWNER#"="U"."USER#")
    17 - filter(DECODE("C"."PROPERTY",0,'NO',DECODE(BITAND("C"."PROPERTY",
    32),32,'YES','NO'))='NO')
    18 - access("O"."OBJ#"="C"."OBJ#")
    19 - filter("C"."INTCOL#"="AC"."INTCOL#"(+))
    20 - access("C"."OBJ#"="H"."OBJ#"(+) AND
    "C"."INTCOL#"="H"."INTCOL#"(+))
    21 - filter("OT"."TYPE#"(+)=13)
    22 - access("AC"."TOID"="OT"."OID$"(+))
    24 - access("OT"."OWNER#"="UT"."USER#"(+))
    25 - filter(BITAND("T"."PROPERTY",512)=512 OR
    BITAND("T"."PROPERTY",8192)=8192)
    26 - access("T"."OBJ#"=:B1)
    29 - access("GRANTEE#"="KZSROROL" AND "OBJ#"=:B1)
    30 - filter("INST_ID"=USERENV('INSTANCE') AND ((-"KZSPRPRV")=(-45) OR
    (-"KZSPRPRV")=(-47) OR (-"KZSPRPRV")=(-48) OR (-"KZSPRPRV")=(-49) OR
    (-"KZSPRPRV")=(-50)))
    31 - filter("O"."TYPE#"=5)
    32 - access("O"."OWNER#"="U"."USER#" AND
    "O"."NAME"='OV_COMMERCIAL_ENTITY_JN')
    33 - filter("S"."NAME"="UCOL"."TABLE_NAME" AND
    "S"."OWNER"="UCOL"."OWNER")
    34 - access("O"."OBJ#"="S"."OBJ#")
    Note
    - rule based optimizer used (consider using cbo)
    === SQL2 ====================================================
    EXPLAIN PLAN FOR
    SELECT UCOL.COLUMN_NAME,
    UCOL.DATA_TYPE
    FROM ALL_SYNONYMS S,
    ALL_TAB_COLUMNS UCOL
    WHERE S.TABLE_OWNER = UCOL.OWNER
    AND S.TABLE_NAME = UCOL.TABLE_NAME
    AND S.owner = 'REPORTING_TEST'
    AND S.SYNONYM_NAME = 'OV_COMMERCIAL_ENTITY_JN'
    Explained.
    SQL>
    SQL> @E:\Oracle\Product\10.2.0\db_1\RDBMS\ADMIN\utlxpls.sql
    Plan hash value: 3285788911
    | Id | Operation | Name |
    | 0 | SELECT STATEMENT | |
    | 1 | TABLE ACCESS BY INDEX ROWID | OBJ$ |
    |* 2 | INDEX UNIQUE SCAN | I_OBJ1 |
    | 3 | TABLE ACCESS BY INDEX ROWID | OBJ$ |
    |* 4 | INDEX UNIQUE SCAN | I_OBJ1 |
    | 5 | TABLE ACCESS BY INDEX ROWID | OBJ$ |
    |* 6 | INDEX UNIQUE SCAN | I_OBJ1 |
    | 7 | TABLE ACCESS BY INDEX ROWID | OBJ$ |
    |* 8 | INDEX UNIQUE SCAN | I_OBJ1 |
    | 9 | TABLE ACCESS BY INDEX ROWID | OBJ$ |
    |* 10 | INDEX UNIQUE SCAN | I_OBJ1 |
    |* 11 | FILTER | |
    | 12 | NESTED LOOPS OUTER | |
    | 13 | NESTED LOOPS OUTER | |
    | 14 | NESTED LOOPS OUTER | |
    | 15 | NESTED LOOPS OUTER | |
    | 16 | NESTED LOOPS | |
    | 17 | NESTED LOOPS | |
    | 18 | NESTED LOOPS | |
    | 19 | NESTED LOOPS | |
    | 20 | NESTED LOOPS | |
    | 21 | TABLE ACCESS BY INDEX ROWID| USER$ |
    |* 22 | INDEX UNIQUE SCAN | I_USER1 |
    |* 23 | TABLE ACCESS BY INDEX ROWID| OBJ$ |
    |* 24 | INDEX RANGE SCAN | I_OBJ2 |
    | 25 | TABLE ACCESS BY INDEX ROWID | SYN$ |
    |* 26 | INDEX UNIQUE SCAN | I_SYN1 |
    | 27 | TABLE ACCESS BY INDEX ROWID | USER$ |
    |* 28 | INDEX UNIQUE SCAN | I_USER1 |
    | 29 | TABLE ACCESS BY INDEX ROWID | OBJ$ |
    |* 30 | INDEX RANGE SCAN | I_OBJ2 |
    |* 31 | TABLE ACCESS CLUSTER | COL$ |
    |* 32 | INDEX UNIQUE SCAN | I_OBJ# |
    |* 33 | TABLE ACCESS CLUSTER | COLTYPE$ |
    |* 34 | INDEX RANGE SCAN | I_HH_OBJ#_INTCOL# |
    |* 35 | TABLE ACCESS BY INDEX ROWID | OBJ$ |
    |* 36 | INDEX RANGE SCAN | I_OBJ3 |
    | 37 | TABLE ACCESS CLUSTER | USER$ |
    |* 38 | INDEX UNIQUE SCAN | I_USER# |
    |* 39 | TABLE ACCESS CLUSTER | TAB$ |
    |* 40 | INDEX UNIQUE SCAN | I_OBJ# |
    | 41 | NESTED LOOPS | |
    | 42 | FIXED TABLE FULL | X$KZSRO |
    |* 43 | INDEX RANGE SCAN | I_OBJAUTH2 |
    |* 44 | FIXED TABLE FULL | X$KZSPR |
    Predicate Information (identified by operation id):
    2 - access("O"."OBJ#"=:B1)
    4 - access("O"."OBJ#"=:B1)
    6 - access("O"."OBJ#"=:B1)
    8 - access("O"."OBJ#"=:B1)
    10 - access("O"."OBJ#"=:B1)
    11 - filter(("O"."TYPE#"=3 OR "O"."TYPE#"=4 OR "O"."TYPE#"=2 AND NOT
    EXISTS (SELECT 0 FROM "SYS"."TAB$" "T" WHERE "T"."OBJ#"=:B1 AND
    (BITAND("T"."PROPERTY",512)=512 OR BITAND("T"."PROPERTY",8192)=8192)))
    AND ("O"."OWNER#"=USERENV('SCHEMAID') OR EXISTS (SELECT 0 FROM
    "SYS"."OBJAUTH$" "OBJAUTH$",SYS."X$KZSRO" "X$KZSRO" WHERE "OBJ#"=:B2
    AND "GRANTEE#"="KZSROROL") OR EXISTS (SELECT 0 FROM SYS."X$KZSPR"
    "X$KZSPR" WHERE "INST_ID"=USERENV('INSTANCE') AND ((-"KZSPRPRV")=(-45)
    OR (-"KZSPRPRV")=(-47) OR (-"KZSPRPRV")=(-48) OR (-"KZSPRPRV")=(-49) OR
    (-"KZSPRPRV")=(-50)))))
    22 - access("U"."NAME"='REPORTING_TEST')
    23 - filter("O"."TYPE#"=5)
    24 - access("O"."OWNER#"="U"."USER#" AND
    "O"."NAME"='OV_COMMERCIAL_ENTITY_JN')
    26 - access("O"."OBJ#"="S"."OBJ#")
    28 - access("S"."OWNER"="U"."NAME")
    30 - access("O"."OWNER#"="U"."USER#" AND "S"."NAME"="O"."NAME")
    31 - filter(DECODE("C"."PROPERTY",0,'NO',DECODE(BITAND("C"."PROPERTY",
    32),32,'YES','NO'))='NO')
    32 - access("O"."OBJ#"="C"."OBJ#")
    33 - filter("C"."INTCOL#"="AC"."INTCOL#"(+))
    34 - access("C"."OBJ#"="H"."OBJ#"(+) AND
    "C"."INTCOL#"="H"."INTCOL#"(+))
    35 - filter("OT"."TYPE#"(+)=13)
    36 - access("AC"."TOID"="OT"."OID$"(+))
    38 - access("OT"."OWNER#"="UT"."USER#"(+))
    39 - filter(BITAND("T"."PROPERTY",512)=512 OR
    BITAND("T"."PROPERTY",8192)=8192)
    40 - access("T"."OBJ#"=:B1)
    43 - access("GRANTEE#"="KZSROROL" AND "OBJ#"=:B1)
    44 - filter("INST_ID"=USERENV('INSTANCE') AND ((-"KZSPRPRV")=(-45) OR
    (-"KZSPRPRV")=(-47) OR (-"KZSPRPRV")=(-48) OR (-"KZSPRPRV")=(-49) OR
    (-"KZSPRPRV")=(-50)))
    Note
    - rule based optimizer used (consider using cbo)

Maybe you are looking for