Here you can find the source of paintCurrentLineBackground(final Graphics g, final JTextComponent c, final Color col)
Parameter | Description |
---|---|
g | Graphics to use. |
c | Text component to work on. |
col | Color to work with. |
public static void paintCurrentLineBackground(final Graphics g, final JTextComponent c, final Color col)
//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); } }