Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 *
 * Copyright (C) 2005-2008 Yves Zoundi
 *
 * 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.
 * under the License.
 */

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;

import javax.swing.JTable;

import javax.swing.table.TableCellRenderer;

public class Main {
    /**
     *
     * @param table
     * @param row
     * @param column
     * @param p
     * @return
     */
    public static boolean pointOutsidePrefSize(JTable table, int row, int column, Point p) {
        if ((table.convertColumnIndexToModel(column) != 0) || (row == -1)) {
            return true;
        }

        TableCellRenderer tcr = table.getCellRenderer(row, column);
        Object value = table.getValueAt(row, column);
        Component cell = tcr.getTableCellRendererComponent(table, value, false, false, row, column);
        Dimension itemSize = cell.getPreferredSize();
        Rectangle cellBounds = table.getCellRect(row, column, false);
        cellBounds.width = itemSize.width;
        cellBounds.height = itemSize.height;

        // See if coords are inside
        // ASSUME: mouse x,y will never be < cell's x,y
        assert ((p.x >= cellBounds.x) && (p.y >= cellBounds.y));

        if ((p.x > (cellBounds.x + cellBounds.width)) || (p.y > (cellBounds.y + cellBounds.height))) {
            return true;
        }

        return false;
    }
}