如何在Java中使复选框不可编辑?
我有一个复选框。我将从数据库获取一个值来确定该复选框是否可以编辑。如果该值为零,则不应选择该复选框。我如何在代码中实现这一点?请帮我一下。这是我的代码:
String status = "0"; // (obtained from the database)
if(status)
{
// should not be editable - can't be selected.
} else {
// can be selected.
}
I have a checkbox. I will obtain one value from a database to determine whether the checkbox can be edited or not. If this value is zero, the checkbox should not be selected. How do I achieve that in code? Please help me out here. This is my code:
String status = "0"; // (obtained from the database)
if(status)
{
// should not be editable - can't be selected.
} else {
// can be selected.
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果这确实是您想要做的,而不是使用带有适当文本和/或图标的 JLabel,您可以为复选框创建一个操作侦听器并让它调用 setSelected:
至少可以说,这不是一个优雅的解决方案,但它确实显示该复选框不可编辑。
If this is REALLY what you want to do instead of using a JLabel with appropriate text and/or icon, you can create an action listener for the checkbox and have it call setSelected:
To say the least, this isn't an elegant solution, but it does give the appearance that the checkbox isn't editable.
使用
setEnabled
方法。Use the
setEnabled
method for that.