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 / GUI / July 2006

Tip: Looking for answers? Try searching our database.

Problem with JCombo box

Thread view: 
srinivas.veeranki@gmail.com - 19 Jul 2006 07:51 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
Bart Cremers - 19 Jul 2006 09:22 GMT
srinivas.veeranki@gmail.com schreef:

> Hi All,
>
[quoted text clipped - 10 lines]
>
> 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@gmail.com - 19 Jul 2006 09:33 GMT
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...

> srinivas.veeranki@gmail.com schreef:
>
[quoted text clipped - 26 lines]
>
> Bart
Larry Barowski - 19 Jul 2006 17:38 GMT
> 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.


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.