9951 explained code solutions for 126 technologies


javaMethod to check if a JTextComponent is empty


public static <T extends JTextComponent> boolean isFieldEmpty (T field) {
  return field.getText().trim().isEmpty();
}ctrl + c
T extends JTextComponent

a generic expression, means the data type T that method takes should be a child of JTextComponent class.

field.getText().trim().isEmpty()

gets the text inside field, trims the whitespace around, returns true if it is an empty string or false on other case.