mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
allow to show hint in non-focused JBTextField if non-empty default value is entered
This commit is contained in:
@@ -50,6 +50,10 @@ public class JBTextField extends JTextField implements ComponentWithEmptyText {
|
||||
myEmptyText = new TextComponentEmptyText(this);
|
||||
}
|
||||
|
||||
public void setTextToTriggerEmptyTextStatus(String t) {
|
||||
myEmptyText.setTextToTriggerStatus(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setText(String t) {
|
||||
super.setText(t);
|
||||
@@ -65,6 +69,11 @@ public class JBTextField extends JTextField implements ComponentWithEmptyText {
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
if (!myEmptyText.getStatusTriggerText().isEmpty() && myEmptyText.isStatusVisible()) {
|
||||
g.setColor(getBackground());
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
g.setColor(getForeground());
|
||||
}
|
||||
myEmptyText.paintStatusText(g);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.intellij.ui.components;
|
||||
|
||||
import com.intellij.util.ui.StatusText;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.text.JTextComponent;
|
||||
import java.awt.*;
|
||||
@@ -27,6 +28,7 @@ import java.awt.event.FocusListener;
|
||||
*/
|
||||
class TextComponentEmptyText extends StatusText {
|
||||
private JTextComponent myOwner;
|
||||
private String myStatusTriggerText = "";
|
||||
|
||||
public TextComponentEmptyText(JTextComponent owner) {
|
||||
super(owner);
|
||||
@@ -45,6 +47,15 @@ class TextComponentEmptyText extends StatusText {
|
||||
});
|
||||
}
|
||||
|
||||
public void setTextToTriggerStatus(@NotNull String defaultText) {
|
||||
myStatusTriggerText = defaultText;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getStatusTriggerText() {
|
||||
return myStatusTriggerText;
|
||||
}
|
||||
|
||||
public void paintStatusText(Graphics g) {
|
||||
getComponent().setFont(myOwner.getFont());
|
||||
paint(myOwner, g);
|
||||
@@ -52,7 +63,7 @@ class TextComponentEmptyText extends StatusText {
|
||||
|
||||
@Override
|
||||
protected boolean isStatusVisible() {
|
||||
return myOwner.getText().isEmpty() && !myOwner.isFocusOwner();
|
||||
return myOwner.getText().equals(myStatusTriggerText) && !myOwner.isFocusOwner();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user