Java JTextComponent Tab paintAboveline(Graphics g, JTextComponent tc, int pos0, int pos1)

Here you can find the source of paintAboveline(Graphics g, JTextComponent tc, int pos0, int pos1)

Description

paint Aboveline

License

Open Source License

Declaration

public static void paintAboveline(Graphics g, JTextComponent tc, int pos0, int pos1)
            throws BadLocationException 

Method Source Code

//package com.java2s;
/*/*w w  w.jav a  2s  .  c o m*/
Copyright (C) 2005  Eduardo Jodas Samper
    
This program 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.
    
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    
   author e-mail: eduardj@dev.java.net
*/

import java.awt.Color;

import java.awt.Graphics;

import java.awt.Rectangle;

import javax.swing.plaf.TextUI;

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

public class Main {
    public static void paintAboveline(Graphics g, JTextComponent tc, int pos0, int pos1)
            throws BadLocationException {
        g.setColor(Color.GREEN.darker());
        TextUI ui = tc.getUI();
        Rectangle r = ui.modelToView(tc, pos1 + 1);
        int h = r.y;

        int max = r.x - 2 + 1;
        int current = ui.modelToView(tc, pos0).x - 1;
        g.drawLine(current, h, max, h);
        g.drawLine(current, h + 1, current, h + 2);
        g.drawLine(max, h + 1, max, h + 2);
    }
}

Related

  1. disableTab(final JTextComponent txtComp)
  2. getTab(JTextComponent target)
  3. getTabSize(JTextComponent text)