EarthWeb
Developer.com
Site
windows 2000
visual c++
java
visual basic
javascripts
recommend it
 
Book
thinking in java
 
Interact
forum
guest book
jobs
jokes
what's new

share code
 
Resource
add resource
modify resource
new resource
 

[Internet Jobs]
-----
Java by E-mail:

Get the weekly e-mail highlights on Java!
-----

-

Display a horizontal scroll bar in the drop down box


Author: Sonal Goyal

The basic function is to display a horizontal scroll bar in the drop down of the JComboBox. It helps to keep the size of the combo small, and yet display strings of varying lengths. The class myCombo is the class where the functionality exists, TestCombo is used to display the combobox.
code for TestCombo:


import com.sun.java.swing.*;
import java.awt.*;
public class TestCombo{

public static void main(String[] args){
    JFrame aFrame = new JFrame();
    myCombo JComboBox1 = new myCombo();
    JComboBox1.setPreferredSize(new Dimension(20,20));
    JComboBox1.setMaximumSize(new Dimension(30,20));
	String[]aArr = {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","BBAAAAAAAAAAA","CCCCC", "DDDDDDDDDDDDD", "EEEEEEEEEEEE","FFFFFFFFFFFFFFFFFFFFFFFFFFFF","GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG","AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","BBAAAAAAAAAAA","CCCCC", "DDDDDDDDDDDDD", "EEEEEEEEEEEE","FFFFFFFFFFFFFFFFFFFFFFFFFFFF","GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"};
	for ( int i= 0; i< aArr.length; ++i)
	JComboBox1.addItem(aArr[i]);
	aFrame.getContentPane().add(JComboBox1);
	aFrame.getContentPane().setSize(100,100);
	aFrame.pack();
	aFrame.show();
}
}

----------------------------------------------------
code for myCombo:
----------------------------------------------------


import com.sun.java.swing.*;
import com.sun.java.swing.plaf.basic.*;

public class myCombo extends JComboBox{
    public myCombo(){
        super();
        setUI(new myComboUI());
    }//end of default constructor
    
    public class myComboUI extends BasicComboBoxUI{
        protected ComboPopup createPopup(){
            BasicComboPopup popup = new BasicComboPopup(comboBox){
                protected JScrollPane createScroller() {
                        return new JScrollPane( list, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED );
              }//end of method createScroller
            };
            return popup;
        }//end of method createPopup
    }//end of inner class myComboUI
}

Posted On: 17-May-1999

internet.commerce



Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy