Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

Problem with JCombo box

Thread view: 
srinivas.veeranki@gmail.com - 17 Jul 2006 11:33 GMT
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 - 17 Jul 2006 12:07 GMT
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?

> Hi All,
>
[quoted text clipped - 9 lines]
>
> Thanks in advance... Here i am giving the code which i tried....
srinivas.veeranki@gmail.com - 17 Jul 2006 12:13 GMT
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

> 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
[quoted text clipped - 13 lines]
> >
> > Thanks in advance... Here i am giving the code which i tried....
Trung Chinh Nguyen - 17 Jul 2006 14:17 GMT
I see the problem now. Don't know what to do with it. Maybe it's some
bug in the ComboBoxModel

> Hi Chinh Nguyen  !
>    Here 2 nd combo box points to first element but the scroll bar of
[quoted text clipped - 4 lines]
>
> Srinivas
srinivas.veeranki@gmail.com - 18 Jul 2006 05:29 GMT
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

> I see the problem now. Don't know what to do with it. Maybe it's some
> bug in the ComboBoxModel
[quoted text clipped - 7 lines]
> >
> > Srinivas


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.