위/아래 화살표 키를 사용하여 JComboBox에서 동일한 선택을하는 경우 주변 선택 항목을 탐색하는 데 도움이되지 않습니다. 어떻게 이런 행동을 피할 수 있습니까?JComboBox의 의도 동작입니까? 어떻게 이런 행동을 피할 수 있습니까?
alt text http://sites.google.com/site/yanchengcheok/Home/jcombobox.png
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
}
내 Mac의 JRE 1.6에서이 코드를 실행하는 레코드의 경우 위로/아래로 키가 올바르게 작동합니다. – Jonik
방금 JRE 1.6과 함께 Ubuntu 10.04에서 사용 했으므로 위아래 키가 작동하지 않습니다. 변경 한 경우 위로/아래로 키는 작동하지만 동일하지 않은 경우에는 작동하지 않습니다. 이상하게 ... 나는 그걸로 계속 놀고 싶어. –
위의 내 의견을 보완하려면 up/down은 작동하지만 한 항목을 선택하고 콤보 상자를 다시 열면 선택 항목이 올바르게 기억되지 않습니다. – Jonik