Problem with JCombo box

Discussion in 'Java' started by srinivas.veeranki@gmail.com, Jul 17, 2006.

  1. Guest

    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
     
    , Jul 17, 2006
    #1
    1. Advertising

  2. 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?

    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, Jul 17, 2006
    #2
    1. Advertising

  3. Guest

    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?
    >
    > 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....
    > >
     
    , Jul 17, 2006
    #3
  4. I see the problem now. Don't know what to do with it. Maybe it's some
    bug in the ComboBoxModel

    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
    >
     
    Trung Chinh Nguyen, Jul 17, 2006
    #4
  5. Guest

    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
    >
    > 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
    > >
     
    , Jul 18, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mit
    Replies:
    1
    Views:
    845
    Ramu Pulipati
    Jan 25, 2006
  2. =?Utf-8?B?QW5nZWw=?=

    COMBO BOX INSTEAD OF DROP DOWN BOX

    =?Utf-8?B?QW5nZWw=?=, Jun 29, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    649
    Ken Cox [Microsoft MVP]
    Jun 29, 2004
  3. SirPoonga
    Replies:
    2
    Views:
    817
    Ben Strackany
    Jan 7, 2005
  4. Gnarlodious
    Replies:
    4
    Views:
    17,710
    elizas
    May 5, 2010
  5. mttc
    Replies:
    3
    Views:
    886
    Michael Rauscher
    Jun 23, 2009
Loading...

Share This Page