Here you can find the source of getColumnNumber(JTextComponent editor, int pos)
Parameter | Description |
---|---|
editor | a parameter |
pos | a parameter |
Parameter | Description |
---|
public static int getColumnNumber(JTextComponent editor, int pos) throws BadLocationException
//package com.java2s; /*/*w w w.ja v a 2 s . c om*/ * Copyright 2008 Ayman Al-Sairafi ayman.alsairafi@gmail.com * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License * at http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.awt.Point; import java.awt.Rectangle; import javax.swing.text.BadLocationException; import javax.swing.text.JTextComponent; public class Main { /** * Gets the column number at given position of editor. The first column is * ZERO * @param editor * @param pos * @return the 0 based column number * @throws javax.swing.text.BadLocationException */ public static int getColumnNumber(JTextComponent editor, int pos) throws BadLocationException { // speedup if the pos is 0 if (pos == 0) { return 0; } Rectangle r = editor.modelToView(pos); int start = editor.viewToModel(new Point(0, r.y)); int column = pos - start; return column; } }