How to listen to JComboBox's width changes?
I tried PropertyChangeListener with property set to "width", "Width", "size" and "Size".
PropertyChangeListener widthChangeListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
//code
}
};
streamsComboBox.addPropertyChangeListener("width", widthChangeListener);
projectsComboBox.addPropertyChangeListener("开发者_JAVA技巧width", widthChangeListener);
vobsComboBox.addPropertyChangeListener("width", widthChangeListener);
Nothing works - the handler method is never fired.
What should I do to handle JComboBox's size change? Where does the property name come from anyway?Try adding a ComponentListener
, for example:
combo.addComponentListener( new ComponentAdapter()
{
public void componentResized( ComponentEvent e )
{
Component component = (Component)e.getSource();
System.out.println( "Resized: " + component.getSize() );
}
});
精彩评论