Problem with JCombo box  
Author Message
srinivas.veeranki





PostPosted: 2006-7-17 18:34:00 Top

java-programmer, Problem with JCombo box 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

 
Trung Chinh Nguyen





PostPosted: 2006-7-17 19:08:00 Top

java-programmer >> Problem with JCombo box Nothing's wrong here. When I select the first combo the second combo
points to the first element (Which is an empty string). Isn't that what
you expected?

email***@***.com wrote:
> 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....
>
 
srinivas.veeranki





PostPosted: 2006-7-17 19:13:00 Top

java-programmer >> Problem with JCombo box Hi Chinh Nguyen !
Here 2 nd combo box points to first element but the scroll bar of
the combo box is not moving to first element. I need to move the scroll
bar of combo box should be at the top not in the moddle. It is
happening at very first time only...Thaks for ur reply ... Plz check
once again.....

Srinivas




Trung Chinh Nguyen wrote:

> Nothing's wrong here. When I select the first combo the second combo
> points to the first element (Which is an empty string). Isn't that what
> you expected?
>
> email***@***.com wrote:
> > 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....
> >

 
 
Trung Chinh Nguyen





PostPosted: 2006-7-17 21:17:00 Top

java-programmer >> Problem with JCombo box I see the problem now. Don't know what to do with it. Maybe it's some
bug in the ComboBoxModel

email***@***.com wrote:
> Hi Chinh Nguyen !
> Here 2 nd combo box points to first element but the scroll bar of
> the combo box is not moving to first element. I need to move the scroll
> bar of combo box should be at the top not in the moddle. It is
> happening at very first time only...Thaks for ur reply ... Plz check
> once again.....
>
> Srinivas
>
 
 
srinivas.veeranki





PostPosted: 2006-7-18 12:30:00 Top

java-programmer >> Problem with JCombo box Hi !
This required to implement this in my project. Client insists us
to achieve this kind of functionality. I tried various ways but in
vain, Can we solve this kind of bug? If u know Please help me.

Thanks

Srinivas
Trung Chinh Nguyen wrote:

> I see the problem now. Don't know what to do with it. Maybe it's some
> bug in the ComboBoxModel
>
> email***@***.com wrote:
> > Hi Chinh Nguyen !
> > Here 2 nd combo box points to first element but the scroll bar of
> > the combo box is not moving to first element. I need to move the scroll
> > bar of combo box should be at the top not in the moddle. It is
> > happening at very first time only...Thaks for ur reply ... Plz check
> > once again.....
> >
> > Srinivas
> >

 
 
srinivas.veeranki





PostPosted: 2006-7-19 14:52:00 Top

java-programmer >> Problem with JCombo box 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

 
 
Bart Cremers





PostPosted: 2006-7-19 16:23:00 Top

java-programmer >> Problem with JCombo box
email***@***.com schreef:

> 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....
>
< code snipped >
>
>
> Thanks & Regards
>
> Srinivas

As far a I can see, I'm not getting the problem you're having. The
second combo always selects and scrolls to the first element when the
first combo changes.

Regards,

Bart

 
 
srinivas.veeranki





PostPosted: 2006-7-19 16:33:00 Top

java-programmer >> Problem with JCombo box Hi !

This problem will be happening only at first time only... If u observe
it ,,,, U can see the problem while ur selecting the first combo...
then observe in the 2nd combo... U will get tht problem...

Bart Cremers wrote:

> email***@***.com schreef:
>
> > 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....
> >
> < code snipped >
> >
> >
> > Thanks & Regards
> >
> > Srinivas
>
> As far a I can see, I'm not getting the problem you're having. The
> second combo always selects and scrolls to the first element when the
> first combo changes.
>
> Regards,
>
> Bart

 
 
Larry Barowski





PostPosted: 2006-7-20 0:38:00 Top

java-programmer >> Problem with JCombo box
<email***@***.com> wrote in message
news:email***@***.com...
> Hi !
>
> This problem will be happening only at first time only... If u observe
> it ,,,, U can see the problem while ur selecting the first combo...
> then observe in the 2nd combo... U will get tht problem...

I confirm the problem with both Windows and Metal L&Fs,
under Java 1.6 beta. I couldn't find this in bug parade, so
you should report it.

I couldn't find any work-around, except to do
cb2.showPopup();
cb2.hidePopup();
but you have to do it when the combo box is showing,
so the flicker of the popup will be visible, which is
probably more annoying than the original problem.