开发者

Display area of a jComboBox

开发者 https://www.devze.com 2023-01-26 12:32 出处:网络
I have this jComboBox on my application.However, some times when I open it, the drop down area is too small to fit all the information that it is suppose to show.Is there any work about so开发者_Stack

I have this jComboBox on my application. However, some times when I open it, the drop down area is too small to fit all the information that it is suppose to show. Is there any work about so开发者_StackOverflow社区 that the drop down area widens to accommodate all the information that it needs to show without increasing the size of the jComboBox?

Thank you.


You are probably looking for Stepped Combo.

The basic idea here is to customize Combobox UI by extending MetalComboBoxUI

Here is a sample code


I was actually going to release this code on my blog this weekend. Here is an early release (I'll update the posting with the real link later). The benefit of this approach is that the functionality is supported by a listener so it should work on any LAF that extends the BasicComboPopop and you don't need to extend any classes. You can just use it like:

JComboBox comboBox = new JComboBox( items );
BoundsPopupMenuListener listener = new BoundsPopupMenuListener(true, false);
comboBox.addPopupMenuListener( listener );

Edit: Check out Combo Box Popup for the final code.

0

精彩评论

暂无评论...
验证码 换一张
取 消