如何检查 JTextField 是否不可编辑

How to check if JTextField is NOT editable

抱歉,如果这是一个简单的问题,但我不完全确定如何检查 JTextField 是否不可编辑?

我知道要检查它是否可编辑,您只需使用

JTextField.isEditable();

但是我如何检查它是否不是?

谢谢

使用逻辑补码运算符(NOT):

if ( !textField.isEditable()){
    .
    .
    .
}

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/opsummary.html

根据 Java 文档 (https://docs.oracle.com/javase/7/docs/api/javax/swing/text/JTextComponent.html#isEditable%28%29),isEditable:

Returns the boolean indicating whether this TextComponent is editable or not.

所以,我想你可以:

if (yourInstance.isEditable() == false) {
    // Your action here
}

甚至:

if (!yourInstance.isEditable()) {
    // Your action here
}