如果在 DefaultListModel 中选择之前单击按钮,可以防止崩溃吗?
我使用 DefaultListModel 在列表中选择不同的名称。要选择名称,用户单击列表中的名称之一,使其突出显示,然后按按钮确认所选名称。我的问题是,如果用户在列表中选择名称之前单击按钮,则会崩溃!
到目前为止,我已经使用了这段代码,但还不足以防止崩溃
if(event.getSource() == buttonSelectCustomer && model1.getSize() > 0)
如果用户在没有任何选择的情况下单击按钮,是否有办法防止崩溃?谢谢!
I'm using a DefaultListModel to select different names in a list. To select a name the user click on one of the name in the list so it get highlited and then confirm the selected name by pressing a button. My problem is if the user click on the button before a name is selected in the list, then it crash!
So far I have used this code, but it's not enough to prevent an crash
if(event.getSource() == buttonSelectCustomer && model1.getSize() > 0)
Is there a way to prevent a crash if user click the button without any selection? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将此添加到您的条件
(list.getSelectedIndex() != -1)
Add this to you condition
(list.getSelectedIndex() != -1)