Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you 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 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. /
package org.apache.cayenne.modeler.util;
import java.awt.*;

public class UIUtil {

Scrolls table within JViewport to the selected row if there is one.
    public static void scrollToSelectedRow(JTable table) {
        int row = table.getSelectedRow();
        if (row >= 0) {
            scroll(tablerow, 0);

Scrolls view if it is located in a JViewport, so that the specified cell is displayed in the center.
    public static void scroll(JTable tableint rowIndexint vColIndex) {
        if (!(table.getParent() instanceof JViewport)) {
        JViewport viewport = (JViewporttable.getParent();
        Rectangle rect = table.getCellRect(rowIndexvColIndextrue);
        Rectangle viewRect = viewport.getViewRect();
        if (viewRect.intersects(rect)) {
        // Translate the cell location so that it is relative
        // to the view, assuming the northwest corner of the
        // view is (0,0).
        rect.setLocation(rect.x - viewRect.xrect.y - viewRect.y);
        // Calculate location of rect if it were at the center of view
        int centerX = (viewRect.width - rect.width) / 2;
        int centerY = (viewRect.height - rect.height) / 2;
        // Fake the location of the cell so that scrollRectToVisible
        // will move the cell to the center
        if (rect.x < centerX) {
            centerX = -centerX;
        if (rect.y < centerY) {
            centerY = -centerY;
        // Scroll the area into view.
"Injects" windows's content to another window
    public static void dock(Window windowWindow dockTo) {
            .add(((RootPaneContainerwindow).getContentPane(), .);
"Injects" windows's content to parent window
    public static void dock(Window window) {
New to GrepCode? Check out our FAQ X