Example usage for javax.swing JViewport getView

List of usage examples for javax.swing JViewport getView

Introduction

In this page you can find the example usage for javax.swing JViewport getView.

Prototype

public Component getView() 

Source Link

Document

Returns the JViewport's one child or null.

Usage

From source file:Main.java

public static boolean canVScroll(JViewport viewport) {
    JScrollPane scrollPane = (JScrollPane) viewport.getParent();
    Rectangle availR = scrollPane.getBounds();

    Component view = viewport.getView();
    Dimension viewPrefSize = view != null ? view.getPreferredSize() : new Dimension(0, 0);
    Dimension extentSize = viewport.toViewCoordinates(availR.getSize());

    boolean canVScroll = true;
    if (view instanceof Scrollable)
        canVScroll = !((Scrollable) view).getScrollableTracksViewportHeight();
    if (canVScroll && (viewPrefSize.height <= extentSize.height))
        canVScroll = false;//from   w  w  w.  j a v a2 s. c  o  m

    return canVScroll;
}

From source file:Main.java

public static boolean canHScroll(JViewport viewport) {
    JScrollPane scrollPane = (JScrollPane) viewport.getParent();
    Rectangle availR = scrollPane.getBounds();

    Component view = viewport.getView();
    Dimension viewPrefSize = view != null ? view.getPreferredSize() : new Dimension(0, 0);
    Dimension extentSize = viewport.toViewCoordinates(availR.getSize());

    boolean canHScroll = true;
    if (view instanceof Scrollable)
        canHScroll = !((Scrollable) view).getScrollableTracksViewportWidth();
    if (canHScroll && (viewPrefSize.width <= extentSize.width))
        canHScroll = false;// ww  w. j  a va2 s  .  c  o m

    return canHScroll;
}

From source file:Main.java

public static void synchronizeView(final JViewport masterViewport, final JViewport slaveViewport,
        final int orientation) {
    final ChangeListener c1 = new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            if (masterViewport.getView() == null || slaveViewport.getView() == null) {
                return;
            }//from   ww  w.  ja  va2s  .c o  m
            if (orientation == SwingConstants.HORIZONTAL) {
                Point v1 = masterViewport.getViewPosition();
                Point v2 = slaveViewport.getViewPosition();
                if (v1.x != v2.x) {
                    slaveViewport.setViewPosition(new Point(v1.x, v2.y));
                }
            } else if (orientation == SwingConstants.VERTICAL) {
                Point v1 = masterViewport.getViewPosition();
                Point v2 = slaveViewport.getViewPosition();
                if (v1.y != v2.y) {
                    slaveViewport.setViewPosition(new Point(v2.x, v1.y));
                }
            }
        }
    };

    masterViewport.addChangeListener(c1);
}

From source file:Main.java

public Main() {
    super();/*from w  ww  . j ava2s  .c  om*/
    JTree tree = new JTree();
    for (int i = 0; i < tree.getRowCount(); i++) {
        tree.expandRow(i);
    }

    final JScrollPane pane = new JScrollPane(tree) {
        Dimension prefSize = new Dimension(200, 150);

        public Dimension getPreferredSize() {
            return prefSize;
        }
    };

    pane.getVerticalScrollBar().addAdjustmentListener(e -> {
        JViewport vp = pane.getViewport();
        if (vp.getView().getHeight() <= vp.getHeight() + vp.getViewPosition().y) {
            System.out.println("End");
        }
    });

    add(pane);
}

From source file:MainClass.java

protected void configureEnclosingScrollPane() {
    Container container = getParent();
    if (container instanceof JViewport) {
        Container viewParent = container.getParent();
        if (viewParent instanceof JScrollPane) {
            JScrollPane scrollPane = (JScrollPane) viewParent;
            JViewport viewport = scrollPane.getViewport();
            if (viewport == null || viewport.getView() != this) {
                return;
            }/*from w w w.j  a  v  a 2s  .co  m*/
            scrollPane.setBorder(UIManager.getBorder("Table.scrollPaneBorder"));
        }
    }
}

From source file:edu.ku.brc.stats.StatGroupTable.java

/**
 * Constructor with the localized name of the Group
 * @param name name of the group (already been localized)
 * @param useSeparator use non-border separator titles
 *///from  ww  w .j  a  v a  2s .  co  m
public StatGroupTable(final String name, final String[] columnNames, final boolean useSeparator,
        final int numRows) {
    this.name = name;
    this.useSeparator = useSeparator;
    this.skinItem = SkinsMgr.getSkinItem("StatGroup");

    if (progressIcon == null) {
        progressIcon = IconManager.getIcon("Progress", IconManager.IconSize.Std16);
    }

    setLayout(new BorderLayout());
    setBackground(Color.WHITE);

    model = new StatGroupTableModel(this, columnNames);
    //table = numRows > SCROLLPANE_THRESOLD ? (new SortableJTable(new SortableTableModel(model))) : (new JTable(model));
    if (numRows > SCROLLPANE_THRESOLD) {
        table = new SortableJTable(new SortableTableModel(model)) {
            protected void configureEnclosingScrollPane() {
                Container p = getParent();
                if (p instanceof JViewport) {
                    Container gp = p.getParent();
                    if (gp instanceof JScrollPane) {
                        JScrollPane scrollPane = (JScrollPane) gp;
                        // Make certain we are the viewPort's view and not, for
                        // example, the rowHeaderView of the scrollPane -
                        // an implementor of fixed columns might do this.
                        JViewport viewport = scrollPane.getViewport();
                        if (viewport == null || viewport.getView() != this) {
                            return;
                        }
                        //                            scrollPane.setColumnHeaderView(getTableHeader());
                        //scrollPane.getViewport().setBackingStoreEnabled(true);
                        scrollPane.setBorder(UIManager.getBorder("Table.scrollPaneBorder"));
                    }
                }
            }
        };
    } else {
        table = new JTable(model) {
            protected void configureEnclosingScrollPane() {
                Container p = getParent();
                if (p instanceof JViewport) {
                    Container gp = p.getParent();
                    if (gp instanceof JScrollPane) {
                        JScrollPane scrollPane = (JScrollPane) gp;
                        // Make certain we are the viewPort's view and not, for
                        // example, the rowHeaderView of the scrollPane -
                        // an implementor of fixed columns might do this.
                        JViewport viewport = scrollPane.getViewport();
                        if (viewport == null || viewport.getView() != this) {
                            return;
                        }
                        //                            scrollPane.setColumnHeaderView(getTableHeader());
                        //scrollPane.getViewport().setBackingStoreEnabled(true);
                        scrollPane.setBorder(UIManager.getBorder("Table.scrollPaneBorder"));
                    }
                }
            }
        };
    }
    table.setShowVerticalLines(false);
    table.setShowHorizontalLines(false);

    if (SkinsMgr.shouldBeOpaque(skinItem)) {
        table.setOpaque(false);
        setOpaque(false);
    } else {
        table.setOpaque(true);
        setOpaque(true);
    }

    table.addMouseMotionListener(new TableMouseMotion());
    table.addMouseListener(new LinkListener());

    if (table.getColumnModel().getColumnCount() == 1) {
        table.getColumnModel().getColumn(0)
                .setCellRenderer(new StatGroupTableCellRenderer(SwingConstants.CENTER, 1));

    } else {
        table.getColumnModel().getColumn(0)
                .setCellRenderer(new StatGroupTableCellRenderer(SwingConstants.LEFT, 2));
        table.getColumnModel().getColumn(1)
                .setCellRenderer(new StatGroupTableCellRenderer(SwingConstants.RIGHT, 2));
    }

    //table.setRowSelectionAllowed(true);

    if (numRows > SCROLLPANE_THRESOLD) {
        scrollPane = new JScrollPane(table, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        if (table instanceof SortableJTable) {
            ((SortableJTable) table).installColumnHeaderListeners();
        }

        scrollPane.setOpaque(false);
        scrollPane.getViewport().setOpaque(false);

        scrollPane.setBorder(BorderFactory.createEmptyBorder());
        //scrollPane.getViewport().setBorder(BorderFactory.createEmptyBorder());
    }

    if (useSeparator) {
        setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
        CellConstraints cc = new CellConstraints();

        if (StringUtils.isNotEmpty(name)) {
            builder.addSeparator(name, cc.xy(1, 1));
        }

        builder.add(scrollPane != null ? scrollPane : table, cc.xy(1, 2));
        builder.getPanel().setOpaque(false);
        add(builder.getPanel());

    } else {
        setBorder(BorderFactory.createEmptyBorder(15, 2, 2, 2));
        setBorder(BorderFactory.createCompoundBorder(new CurvedBorder(new Color(160, 160, 160)), getBorder()));

        add(scrollPane != null ? scrollPane : table, BorderLayout.CENTER);
    }
}

From source file:com.projity.pm.graphic.spreadsheet.common.CommonSpreadSheet.java

protected void configureEnclosingScrollPane() {
    super.configureEnclosingScrollPane();
    Container p = getParent();//from   www .j  av  a 2 s .c o m
    if (p instanceof JViewport) {
        Container gp = p.getParent();
        if (gp instanceof JScrollPane) {
            JScrollPane scrollPane = (JScrollPane) gp;
            JViewport viewport = scrollPane.getViewport();
            if (viewport == null || viewport.getView() != this)
                return;

            configureScrollPaneHeaders(scrollPane);

            Border border = scrollPane.getBorder();
            if (border == null || border instanceof UIResource) {
                scrollPane.setBorder(UIManager.getBorder("Table.scrollPaneBorder"));
            }
        }
    }
}

From source file:net.lmxm.ute.gui.MainFrame.java

/**
 * Clear input validators for current editor.
 *///from  w w  w .java  2 s . c om
private void clearInputValidatorsForCurrentEditor() {
    final JScrollPane scrollPane = getJobDetailsEditorScrollPane();
    if (scrollPane != null) {
        final JViewport viewport = scrollPane.getViewport();

        if (viewport != null) {
            final Component view = viewport.getView();

            if (view instanceof AbstractEditorPanel) {
                ((AbstractEditorPanel) view).clearInputValidators();
            }
        }
    }
}

From source file:org.fit.cssbox.scriptbox.demo.tester.JavaScriptTesterUIPresenter.java

private JEditorPane getSelectedEditorPane() {
    JScrollPane scrollPane = (JScrollPane) sourceCodeTabbedPane.getSelectedComponent();
    JViewport viewport = scrollPane.getViewport();
    return (JEditorPane) viewport.getView();
}

From source file:org.pentaho.reporting.engine.classic.core.modules.gui.base.parameters.TextAreaParameterComponentTest.java

private JTextArea findTextArea(TextAreaParameterComponent comp) {
    JTextArea result = null;// w  w w.j av  a 2  s. c  om
    if (comp.getComponentCount() > 0) {
        for (int i = 0; i < comp.getComponentCount(); i++) {
            if (comp.getComponent(i) instanceof JViewport) {
                JViewport viewport = (JViewport) comp.getComponent(i);
                result = (JTextArea) viewport.getView();
            }
        }
    }
    return result;
}