PromptSupport { public static void setPrompt(String promptText, JTextComponent textComponent) { TextUIWrapper.getDefaultWrapper().install(textComponent, true); if (textComponent.getToolTipText() == null || textComponent.getToolTipText().equals(getPrompt(textComponent))) { textComponent.setToolTipText(promptText); } textComponent.putClientProperty(PROMPT, promptText); textComponent.repaint(); } private  PromptSupport(); static void init(String promptText, Color promptForeground, Color promptBackground,
			final JTextComponent textComponent); static FocusBehavior getFocusBehavior(JTextComponent textComponent); static void setFocusBehavior(FocusBehavior focusBehavior, JTextComponent textComponent); static String getPrompt(JTextComponent textComponent); static void setPrompt(String promptText, JTextComponent textComponent); static Color getForeground(JTextComponent textComponent); static void setForeground(Color promptTextColor, JTextComponent textComponent); static Color getBackground(JTextComponent textComponent); static void setBackground(Color background, JTextComponent textComponent); @SuppressWarnings("unchecked") static Painter<? super T> getBackgroundPainter(T textComponent); static void setBackgroundPainter(Painter<? super T> background, T textComponent); static void setFontStyle(Integer fontStyle, JTextComponent textComponent); static Integer getFontStyle(JTextComponent textComponent); static final String PROMPT; static final String FOREGROUND; static final String BACKGROUND; static final String BACKGROUND_PAINTER; static final String FOCUS_BEHAVIOR; static final String FONT_STYLE; }
@Test public void testSetPrompt() throws Exception { PromptSupport.setPrompt("test", txt); assertEquals("test", PromptSupport.getPrompt(txt)); assertEquals("test", txt.getClientProperty(PromptSupport.PROMPT)); assertEquals("test", txt.getToolTipText()); promptSupportMustStayInstalled(); PromptSupport.setPrompt("test2", txt); assertEquals("test2", txt.getToolTipText()); txt.setToolTipText("ttt"); PromptSupport.setPrompt("test3", txt); assertEquals("ttt", txt.getToolTipText()); }