views:

100

answers:

1

I realize that if you are having a same selection in JComboBox, using up/down arrow key, will not help you to navigate the selection around. How I can avoid this behavior?

See the screenshot below:

alt text

public class NewJFrame extends javax.swing.JFrame {

    /** Creates new form NewJFrame */
    public NewJFrame() {
        initComponents();

        /* If you are having 3 same strings here. Using, up/down arrow key,
         * will not move the selection around.
         */
        this.jComboBox1.addItem("Intel");
        this.jComboBox1.addItem("Intel");
        this.jComboBox1.addItem("Intel");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jComboBox1 = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jComboBox1.setEditable(true);

        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(105, 105, 105)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(137, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(63, 63, 63)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(217, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new NewJFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JComboBox jComboBox1;
    // End of variables declaration                   
}
+2  A: 

Quit cross posting.

The answer has already been given in that posting.

camickr
funny, is that you that answered it on the sun forums? :)
willcodejavaforfood
Yes, that is how I know it is cross posted. I spend time on many forums and try to warn when cross posters are found so we don't waste time answering questions that have already been answered. Then next time the OP does this I just ignore the question and warn everybody so hopefully they ignore it as well.
camickr
If you copied your answer here, I'd be more willing to upvote you. :) (Yeah, that would violate DRY, but it's good to have answers right here on SO. I guess I tend to think it's more likely that the Sun.. er, *Oracle* Java forums disappear off the web than SO...)
Jonik
@ Jonik, that is why I despise cross posters. All the information should be in one place so a discussion can take place in one place. Therefore the solution should only be in one place in case someone wants to make additional comments. Having code and comments in two different places is too hard to manage.
camickr