Java JTextComponent paintCurrentLineBackground(final Graphics g, final JTextComponent c, final Color col)

Here you can find the source of paintCurrentLineBackground(final Graphics g, final JTextComponent c, final Color col)

Description

Paint current line background area with #getLineHighlighterBackgroundColor() .

License

Open Source License

Parameter

Parameter Description
g Graphics to use.
c Text component to work on.
col Color to work with.

Declaration

public static void paintCurrentLineBackground(final Graphics g, final JTextComponent c, final Color col) 

Method Source Code


//package com.java2s;
/* This file is part of the project "Hilbert II" - http://www.qedeq.org
 *
 * Copyright 2000-2013,  Michael Meyling <mime@qedeq.org>.
 *
 * "Hilbert II" is free software; you can redistribute
 * it and/or modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *//*from  www.j  a va2 s .co m*/

import java.awt.Color;

import java.awt.Graphics;

import java.awt.Rectangle;

import javax.swing.text.BadLocationException;
import javax.swing.text.JTextComponent;

public class Main {
    /**
     * Paint current line background area with
     * {@link #getLineHighlighterBackgroundColor()}.
     *
     * @param   g   Graphics to use.
     * @param   c   Text component to work on.
     * @param   col Color to work with.
     */
    public static void paintCurrentLineBackground(final Graphics g, final JTextComponent c, final Color col) {
        // if something is selected we don't highlight
        if (c.getSelectionStart() != c.getSelectionEnd()) {
            return;
        }
        Rectangle r;
        try {
            r = c.modelToView(c.getCaretPosition());
        } catch (BadLocationException couldNotHappen) {
            throw new RuntimeException(couldNotHappen);
        }
        g.setColor(col);
        g.fillRect(0, r.y, c.getWidth(), r.height);
    }
}

Related

  1. isNonWhitespaceBetween(JTextComponent editor, int iStart, int iEnd)
  2. loadFileToPane(String fname, JTextComponent pane)
  3. loadTextToPane(String text, JTextComponent pane, boolean append)
  4. makeVisible(JTextComponent textPane, int start, int end)
  5. maxLength(JTextComponent textComponent, int length)
  6. paintUnderline(Graphics g, JTextComponent tc, int pos0, int pos1)
  7. parseDouble(JTextComponent textComponent)
  8. readOnly(JTextComponent c, Component parent)
  9. refreshJTextComponent(JTextComponent textComponent)