【问题标题】:Disabling swing components based on radio buttons when program starts在程序启动时禁用基于单选按钮的摆动组件
【发布时间】:2013-12-10 20:27:24
【问题描述】:

我想根据一组单选按钮禁用某些摆动组件。最初选择其中一个单选按钮,但在单击其中一个按钮之前它不会禁用组件。我怎样才能使文本字段默认关闭?

这对我有帮助。

        private void cCipherActionPerformed(java.awt.event.ActionEvent evt) {                                        
    if (cCipher.isSelected()) {
        cipherText.setEnabled(false);
        cipherLetterSelect.setEnabled(true);
    }
}                                       

private void vCipherActionPerformed(java.awt.event.ActionEvent evt) {                                        
    if (vCipher.isSelected()) {
        cipherLetterSelect.setEnabled(false);
        cipherText.setEnabled(true);
    }
}

【问题讨论】:

  • How can i make it so that a text field is off by default? 在初始化后立即调用setEnable(false)

标签: java swing


【解决方案1】:

根据我的理解,这很简单:以 cipherText 为例,您可以在类的开头创建 JTextField 实例:

JTextField cipherText = new JTextField();

然后在特定类的构造函数中将其设置为禁用

public MyClass(){

    cipherText.setEnabled(false);  

}

【讨论】:

    猜你喜欢
    • 2017-12-28
    • 2011-09-15
    • 2020-03-08
    • 2012-11-28
    • 1970-01-01
    • 2012-05-23
    • 2010-12-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多