Code example for JTextComponent

Methods: getCaretgetText

0
 
	protected void paintPromptComponent(Graphics g, JTextComponent txt) {
		JTextComponent lbl = getPromptComponent(txt);
		lbl.paint(g);
 
		if (txt.getCaret() != null) {
			txt.getCaret().paint(g);
		} 
	} 
 
	/** 
	 * Returns if the prompt or the text field should be painted, depending on 
	 * the state of <code>txt</code>. 
	 *  
	 * @param txt 
	 * @return true when <code>txt</code> contains not text, otherwise false 
	 */ 
	public boolean shouldPaintPrompt(JTextComponent txt) {
		return txt.getText() == null || txt.getText().length() == 0;
	} 
 
	/** 
	 * Calls super.{@link #update(Graphics, JComponent)}, which in turn calls 
	 * the paint method of this object.