use of javax.swing.plaf.synth.SynthTextFieldUI in project frostwire by frostwire.
the class PromptTextUI method getPromptComponent.
/**
* Creates a label component, if none has already been created. Sets the
* prompt components properties to reflect the given {@link JTextComponent}s
* properties and returns it.
*
* @param txt
* @return the adjusted prompt component
*/
public JTextComponent getPromptComponent(JTextComponent txt) {
if (promptComponent == null) {
promptComponent = createPromptComponent();
promptComponent.setUI(new SynthTextFieldUI());
}
if (txt.isFocusOwner() && PromptSupport.getFocusBehavior(txt) == FocusBehavior.HIDE_PROMPT) {
promptComponent.setText(null);
} else {
promptComponent.setText(PromptSupport.getPrompt(txt));
}
if (promptComponent.getHighlighter() != null) {
promptComponent.getHighlighter().removeAllHighlights();
}
if (txt.isFocusOwner() && PromptSupport.getFocusBehavior(txt) == FocusBehavior.HIGHLIGHT_PROMPT) {
promptComponent.setForeground(txt.getSelectedTextColor());
try {
promptComponent.getHighlighter().addHighlight(0, promptComponent.getText().length(), new DefaultHighlightPainter(txt.getSelectionColor()));
} catch (BadLocationException e) {
e.printStackTrace();
}
} else {
promptComponent.setForeground(PromptSupport.getForeground(txt));
}
if (PromptSupport.getFontStyle(txt) == null) {
promptComponent.setFont(txt.getFont());
} else {
promptComponent.setFont(txt.getFont().deriveFont(PromptSupport.getFontStyle(txt)));
}
promptComponent.setBackground(PromptSupport.getBackground(txt));
promptComponent.setEnabled(txt.isEnabled());
promptComponent.setOpaque(txt.isOpaque());
promptComponent.setBounds(txt.getBounds());
promptComponent.setBorder(txt.getBorder());
promptComponent.setSelectedTextColor(txt.getSelectedTextColor());
promptComponent.setSelectionColor(txt.getSelectionColor());
promptComponent.setEditable(txt.isEditable());
promptComponent.setMargin(txt.getMargin());
return promptComponent;
}
Aggregations