gpt4 book ai didi

java - 如何区分 JComboBox 中的 setSelectedItem 调用和 actionPerformed 方法

转载 作者:行者123 更新时间:2023-12-02 12:10:08 24 4
gpt4 key购买 nike

我有一个在 JComboBox 中值更改事件时调用的方法

public void actionPerformed( ActionEvent e )
{
Object source = e.getSource();
if( source.equals( listComboBox ) )
{
changeList();
}
}


public void changeList()
{ //do some stuff
.....
.....
//warn the user
}

我的问题是这个方法也在初始加载方法中被调用。在该方法中会弹出警告消息。仅当用户更改组合框的选定值时才需要。(当我在加载方法的代码中设置值时不需要。)

有没有办法(标志,不同的方法)来区分这些操作并仅在需要时才给出警告消息?

最佳答案

My problem is that this method is called at the initial load method as well.

因此,在加载完成后将监听器添加到组合框。

关于java - 如何区分 JComboBox 中的 setSelectedItem 调用和 actionPerformed 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46607198/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com