Code example for JTextComponent

Methods: getSelectionEndgetSelectionStartgetTextisEditable

0
		} 
		if (target instanceof JPasswordField) {
			this.copyMenuItem.setEnabled(false);
			this.cutMenuItem.setEnabled(false);
		} else { 
			if (target.getSelectionStart() != target.getSelectionEnd()) {
				this.copyMenuItem.setEnabled(true);
			} else { 
				this.copyMenuItem.setEnabled(false);
			} 
			if ((target.getSelectionStart() != target.getSelectionEnd()) && target.isEditable()) {
				this.cutMenuItem.setEnabled(true);
			} else { 
				this.cutMenuItem.setEnabled(false);
			} 
		} 
 
		if (target.isEditable()) {
			this.pasteMenuItem.setEnabled(true);
		} else { 
			this.pasteMenuItem.setEnabled(false);
		} 
		if (target.isEditable() && (target.getSelectionStart() != target.getSelectionEnd())) {
			this.deleteMenuItem.setEnabled(true);
		} else { 
			this.deleteMenuItem.setEnabled(false);
		} 
		if (getTextLength(target) > 0) {
			this.selectAllMenuItem.setEnabled(true);
		} else { 
			this.selectAllMenuItem.setEnabled(false);
		} 
//		if ((getTextLength(target) > 0) && target.isEditable()) { 
//			this.clearMenuItem.setEnabled(true); 
//		} else { 
//			this.clearMenuItem.setEnabled(false); 
//		} 
		super.show(invoker, x, y);
		this.parent.requestFocus();
	} 
 
	private int getTextLength(JTextComponent c) {
		if (c == null) {
			return 0; 
		} 
		if (c.getText() == null) {
			return 0; 
		} 
		return c.getText().length();
	} 
 
	@Override 
	public void setVisible(boolean val) {
		try {