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

The following examples show how to use javax.swing.text.JTextComponent#setBackground() . 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: AdjudicationCellRenderer.java    From mae-annotation with GNU General Public License v3.0 6 votes vote down vote up
@Override
public JTextComponent getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {

    JTextComponent renderer = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);

    renderer.setBackground(dataModel.isGoldTagRow(table.convertRowIndexToModel(row)) ? getBackground() : nonGoldRowBackground);
    int lastMinimalColumn = associatedType.isExtent() ? TablePanelController.TEXT_COL : Collections.max(((TagTableModel) dataModel).getTextColumns());

    if (!dataModel.isGoldTagRow(table.convertRowIndexToModel(row))) {
        if (col == TablePanelController.SRC_COL) {
            renderer.setForeground(tablePanelController.getMainController().getDocumentColor((String) value));
            renderer.setBorder(null);
        } else if (((TagTableModel) dataModel).isTextColumn(col) || col > lastMinimalColumn) {
            java.util.List[] distribution = getValueDistribution(dataModel, col);
            if (distribution != null) {
                renderer.setBorder(getAgreementIndicator(distribution, (String) value));
            }
        } else {
            renderer.setBorder(null);
        }
    } else {
        renderer.setBackground(UIManager.getColor("Table.background")); // do not change background on selection
    }

    return renderer;
}
 
Example 2
Source File: ComboInplaceEditor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void prepareEditor() {
    Component c = getEditor().getEditorComponent();

    if (c instanceof JTextComponent) {
        JTextComponent jtc = (JTextComponent) c;
        String s = jtc.getText();

        if ((s != null) && (s.length() > 0)) {
            jtc.setSelectionStart(0);
            jtc.setSelectionEnd(s.length());
        }

        if (tableUI) {
            jtc.setBackground(getBackground());
        } else {
            jtc.setBackground(PropUtils.getTextFieldBackground());
        }
        if( tableUI )
            jtc.requestFocus();
    }

    if (getLayout() != null) {
        getLayout().layoutContainer(this);
    }

    repaint();
}
 
Example 3
Source File: OutputTab.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Set text view background color correctly. See bug #225829.
 */
private void setTextViewBackground(JTextComponent textView, Color bg) {
    getOutputPane().getTextView().setBackground(bg);
    getOutputPane().getFoldingSideBar().setBackground(bg);
    if ("Nimbus".equals(UIManager.getLookAndFeel().getName())) { //NOI18N
        UIDefaults defaults = new UIDefaults();
        defaults.put("EditorPane[Enabled].backgroundPainter", bg);  //NOI18N
        textView.putClientProperty("Nimbus.Overrides", defaults);   //NOI18N
        textView.putClientProperty(
                "Nimbus.Overrides.InheritDefaults", true);          //NOI18N
        textView.setBackground(bg);
    }
}
 
Example 4
Source File: DocumentViewOp.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void applyDefaultColoring(JTextComponent textComponent) { // Called in AWT to possibly apply default coloring from settings
    AttributeSet coloring = defaultColoring;
    Font font = ViewUtils.getFont(coloring);
    if (font != null) {
        textComponent.setFont(font);
    }
    Color foreColor = (Color) coloring.getAttribute(StyleConstants.Foreground);
    if (foreColor != null) {
        textComponent.setForeground(foreColor);
    }
    Color backColor = (Color) coloring.getAttribute(StyleConstants.Background);
    if (backColor != null) {
        textComponent.setBackground(backColor);
    }
}
 
Example 5
Source File: FlutterProjectStep.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void updateSdkField(JTextComponent sdkEditor) {
  FlutterSdk current = FlutterSdk.forPath(sdkEditor.getText());
  Color color = sdkBackgroundColor;
  if (current == null) {
    if (ColorUtil.isDark(sdkBackgroundColor)) {
      color = ColorUtil.darker(JBColor.YELLOW, 5);
    }
    else {
      color = ColorUtil.desaturate(JBColor.YELLOW, 15);
    }
  }
  sdkEditor.setBackground(color);
}
 
Example 6
Source File: FlutterProjectStep.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void updateSdkField(JTextComponent sdkEditor) {
  FlutterSdk current = FlutterSdk.forPath(sdkEditor.getText());
  Color color = sdkBackgroundColor;
  if (current == null) {
    if (ColorUtil.isDark(sdkBackgroundColor)) {
      color = ColorUtil.darker(JBColor.YELLOW, 5);
    }
    else {
      color = ColorUtil.desaturate(JBColor.YELLOW, 15);
    }
  }
  sdkEditor.setBackground(color);
}
 
Example 7
Source File: DialogEditor.java    From ET_Redux with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param textComp
 * @param editable
 */
public UnDoAbleDocument(JTextComponent textComp, boolean editable) {
    this(textComp);
    textComp.setEditable(editable);
    if (editable) {
        textComp.setBackground(ReduxConstants.myEditingWhiteColor);
    } else {
        textComp.setBackground(ReduxConstants.myNotEditingGreyColor);
    }

    textComp.addFocusListener(new SelectTextFocusListener());
}
 
Example 8
Source File: AnnotationCellRenderer.java    From mae-annotation with GNU General Public License v3.0 5 votes vote down vote up
@Override
public JTextComponent getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
    Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
    JTextComponent renderer;

    if (((TagTableModel) table.getModel()).isTextColumn(col)) {
        renderer = new JTextPane();
        int fontSize = c.getFont().getSize();
        ((JTextPane) renderer).setContentType("text/plain; charset=UTF-8");
        ((JTextPane) renderer).setStyledDocument(
                FontHandler.stringToSimpleStyledDocument(
                        (String) value, "dialog", fontSize, getCellForeground(isSelected)));
    } else {
        renderer = new JTextArea((String) value);
        renderer.setFont(c.getFont());
    }

    if (col == TablePanelController.SRC_COL) {
        renderer.setText(FileHandler.getFileBaseName(getText()));
    }

    renderer.setMargin(new Insets(0, 2, 0, 2));
    renderer.setOpaque(true);
    renderer.setForeground(getCellForeground(isSelected));
    renderer.setToolTipText(value == null ? " " : (String) value);
    renderer.setBackground(c.getBackground());
    renderer.setBorder(hasFocus ?
            UIManager.getBorder("Table.focusCellHighlightBorder")
            : BorderFactory.createEmptyBorder(1, 1, 1, 1));

    return renderer;
}
 
Example 9
Source File: FrameUtil.java    From yawl with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void readOnly(JTextComponent c, JComponent parent) {
  c.setEditable(false);
  c.setForeground(parent.getForeground());
  c.setBackground(parent.getBackground());
}
 
Example 10
Source File: ExportZipDialog.java    From tracker with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void documentChanged(DocumentEvent e) {
  	JTextComponent field = (JTextComponent)e.getDocument().getProperty("parent"); //$NON-NLS-1$
  	field.setBackground(Color.yellow);
		field.setForeground(defaultForeground);
  }