S
srinivas.veeranki
Hi All,
Here i am getting the problem with JCombobox. Here i am taking 2 combo
boxes. each of them has 11 elements. They have set the initiall
selected items. If I select the first combo then i am setting
setSelectedIndex(0) for 2nd combo. In this , the scrollbar is not
moving to first element or blank element. From the next time onwords,
the scroll bar also moving to the first element. I need to put the
scroll bar at first element when ever i selected the combo box which is
set to first element or null element. Please help me regaurding
this....
Thanks in advance... Here i am giving the code which i tried....
/*
* Main.java
*
* Created on July 17, 2006, 10:31 AM
*/
package Test;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.UIManager;
import java.awt.BorderLayout;
import javax.swing.UnsupportedLookAndFeelException;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
/**
*
* @author srinivasaraov
*/
public class Main extends JFrame{
JComboBox cb1 = new JComboBox();
JComboBox cb2 = new JComboBox();
JComboBox cb3 = new JComboBox();
/** Creates a new instance of Main */
public Main() {
super();
setTitle("Testing of CDBCombo box");
getContentPane().setLayout(new BorderLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
cb1.addItem("");
cb1.addItem("One");
cb1.addItem("Two");
cb1.addItem("Three");
cb1.addItem("Four");
cb1.addItem("Five");
cb1.addItem("Six");
cb1.addItem("Seven");
cb1.addItem("Eight");
cb1.addItem("Nine");
cb1.addItem("Ten");
cb2.addItem("");
cb2.addItem("AB");
cb2.addItem("BC");
cb2.addItem("CD");
cb2.addItem("DE");
cb2.addItem("EF");
cb2.addItem("FG");
cb2.addItem("GH");
cb2.addItem("HI");
cb2.addItem("IJ");
cb2.addItem("JKL");
cb1.setSelectedIndex(2);
cb2.setSelectedIndex(3);
cb1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cb2.setSelectedIndex(0);
}
});
cb1.setMaximumRowCount(4);
cb2.setMaximumRowCount(4);
getContentPane().add(cb1, BorderLayout.NORTH);
getContentPane().add(cb2,BorderLayout.CENTER);
//getContentPane().add(cb3, BorderLayout.SOUTH);
pack();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
new Main().show();
}
}
Thanks & Regards
Srinivas
Here i am getting the problem with JCombobox. Here i am taking 2 combo
boxes. each of them has 11 elements. They have set the initiall
selected items. If I select the first combo then i am setting
setSelectedIndex(0) for 2nd combo. In this , the scrollbar is not
moving to first element or blank element. From the next time onwords,
the scroll bar also moving to the first element. I need to put the
scroll bar at first element when ever i selected the combo box which is
set to first element or null element. Please help me regaurding
this....
Thanks in advance... Here i am giving the code which i tried....
/*
* Main.java
*
* Created on July 17, 2006, 10:31 AM
*/
package Test;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.UIManager;
import java.awt.BorderLayout;
import javax.swing.UnsupportedLookAndFeelException;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
/**
*
* @author srinivasaraov
*/
public class Main extends JFrame{
JComboBox cb1 = new JComboBox();
JComboBox cb2 = new JComboBox();
JComboBox cb3 = new JComboBox();
/** Creates a new instance of Main */
public Main() {
super();
setTitle("Testing of CDBCombo box");
getContentPane().setLayout(new BorderLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
cb1.addItem("");
cb1.addItem("One");
cb1.addItem("Two");
cb1.addItem("Three");
cb1.addItem("Four");
cb1.addItem("Five");
cb1.addItem("Six");
cb1.addItem("Seven");
cb1.addItem("Eight");
cb1.addItem("Nine");
cb1.addItem("Ten");
cb2.addItem("");
cb2.addItem("AB");
cb2.addItem("BC");
cb2.addItem("CD");
cb2.addItem("DE");
cb2.addItem("EF");
cb2.addItem("FG");
cb2.addItem("GH");
cb2.addItem("HI");
cb2.addItem("IJ");
cb2.addItem("JKL");
cb1.setSelectedIndex(2);
cb2.setSelectedIndex(3);
cb1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cb2.setSelectedIndex(0);
}
});
cb1.setMaximumRowCount(4);
cb2.setMaximumRowCount(4);
getContentPane().add(cb1, BorderLayout.NORTH);
getContentPane().add(cb2,BorderLayout.CENTER);
//getContentPane().add(cb3, BorderLayout.SOUTH);
pack();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
new Main().show();
}
}
Thanks & Regards
Srinivas