tags:

views:

50

answers:

2

By referring to the answer at Multi Columns Combo Box for Swing, I manage to implement a 3 multi columns JComboBox as follow.

alt text

However, this is not perfect. My intention is to have something without the horizontal scroll bar, as follow. alt text

My question is, how can I have a JComboBox drop down list, which is wider than the JComboBox itself? I just want to get rid of the horizontal scroll bar. Yet, able to fit in 3 columns into a single list.

The source code are ResultSetCellRenderer and AjaxAutoCompleteJComboBox

A: 

Try making custom.
Here is the code snippet

private static class PopupExpandingComboBoxUI extends WindowsComboBoxUI
{
protected ComboPopup createPopup()
{
return new ExpandingComboPopup(comboBox);
}
}
// Our custom popup menu - it makes up its own width
private static class ExpandingComboPopup extends BasicComboPopup
{
public ExpandingComboPopup(JComboBox cBox)
{
super(cBox);
}
public Rectangle computePopupBounds(int px, int py, int pw, int ph)
{
// Ok - just set the popup width to 200 for now - should be calculated though
return super.computePopupBounds(px, py, 200, ph);
}
}  

Source:http://www.thatsjava.com/java-programming/94874/

org.life.java
Instead of using magic number 200, what is the correct way to perform the computation?
Yan Cheng CHEOK
@Yan Cheng give it +100than your combo box size under unexpanded situation
org.life.java
What if user change to different look n feel. For example, Linux user will have GNOME look n feel. If I am develop within Windows machine, I will not have access to GNOME's ComboBox UI.
Yan Cheng CHEOK
@Yan Cheng CHEOK I meant combobox.getSize()+100 (don't remember exact method for this but explore doc you will get it)
org.life.java
No. I mean, your solution only work when user are choosing Windows Look and Feel. How about Nimbus look and feel, GTK+ look and feel? FYI, we do not have direct access to Nimbus and GTK+ classes.
Yan Cheng CHEOK
+1  A: 

I got my problem resolved through the following forum Oracle Java Swing Forum

For future reference, I include the complete workable source code, for anyone who are interested.

AjaxAutoCompleteJComboBox.java

Yan Cheng CHEOK
Which part in particular?
jjnguy