开发者

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() );
  }
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜