Java Code Examples for javax.swing.text.JTextComponent#getForeground()

The following examples show how to use javax.swing.text.JTextComponent#getForeground() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OutputView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void paint(Graphics g, Shape a) {
    ((Graphics2D) g).addRenderingHints(getHints());

    Container container = getContainer();
    if (container instanceof JTextComponent) {
        final JTextComponent textComp = (JTextComponent) container;
        selStart = textComp.getSelectionStart();
        selEnd = textComp.getSelectionEnd();
        unselectedFg = textComp.isEnabled()
                ? textComp.getForeground()
                : textComp.getDisabledTextColor();
        selectedFg = textComp.getCaret().isSelectionVisible()
                ? textComp.getSelectedTextColor()
                : unselectedFg;
    }
    super.paint(g, a);
}
 
Example 2
Source File: FadingDemo.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void setTextAndAnimate(final JTextComponent textComponent,
        final String text) {
   Color c = textComponent.getForeground();

   KeyFrames keyFrames = new KeyFrames(KeyValues.create(
               new Color(c.getRed(), c.getGreen(), c.getBlue(), 255),
               new Color(c.getRed(), c.getGreen(), c.getBlue(), 0),
               new Color(c.getRed(), c.getGreen(), c.getBlue(), 255)
           ));
   PropertySetter setter = new PropertySetter(textComponent, "foreground",
           keyFrames);

   Animator animator = new Animator(200, setter);
   animator.addTarget(new TimingTargetAdapter() {
       private boolean textSet = false;

       public void timingEvent(float fraction) {
           if (fraction >= 0.5f && !textSet) {
               textComponent.setText(text);
               textSet = true;
           }
       } 
   });
   animator.start();
}
 
Example 3
Source File: HighlightsViewUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static Color validForeColor(AttributeSet attrs, JTextComponent textComponent) {
    Color foreColor = foreColor(attrs);
    if (foreColor == null) {
        foreColor = textComponent.getForeground();
    }
    if (foreColor == null) {
        foreColor = Color.BLACK;
    }
    return foreColor;
}
 
Example 4
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
@Override public void focusGained(FocusEvent e) {
  JTextComponent textField = (JTextComponent) e.getComponent();
  String str = textField.getText();
  Color col = textField.getForeground();
  if (ghostMessage.equals(str) && INACTIVE_COLOR.equals(col)) {
    textField.setForeground(ORIGINAL_COLOR);
    textField.setText("");
  }
}