Example usage for javax.swing JComponent getHeight

List of usage examples for javax.swing JComponent getHeight

Introduction

In this page you can find the example usage for javax.swing JComponent getHeight.

Prototype

@BeanProperty(bound = false)
public int getHeight() 

Source Link

Document

Returns the current height of this component.

Usage

From source file:ua.com.fielden.platform.example.swing.egi.EgiExample.java

private void addTotalsFooterTo(final EntityGridInspector egi, final JPanel topPanel) {
    //   final JPanel panel = new JPanel(new MigLayout("insets 0", "[]", "[]0[]push[]"));
    //   panel.add(egi.getTableHeader(), "grow, wrap");
    //   panel.add(egi, "grow, wrap");

    final JScrollPane scrollPane = new JScrollPane(egi);
    topPanel.add(scrollPane, "grow, wrap");

    final JPanel footer = new JPanel(new MigLayout("nogrid, insets 0"));
    //   footer.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
    final List<JComponent> totalsComponents = new ArrayList<JComponent>();
    for (int i = 0; i < egi.getColumnCount(); i++) {
        final TableColumn column = egi.getColumnModel().getColumn(i);
        final JComponent totalsComponent = i % 2 == 0 ? new JTextField("totals " + i) : new JLabel();
        totalsComponent.setPreferredSize(new Dimension(column.getPreferredWidth(), 30));

        footer.add(totalsComponent, "grow");
        totalsComponents.add(totalsComponent);
    }// w w  w  .j  ava  2s. co  m

    final JScrollPane footerPane = new JScrollPane(footer, JScrollPane.VERTICAL_SCROLLBAR_NEVER,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    topPanel.add(footerPane, "grow, wrap, h 40::");
    topPanel.add(scrollPane.getHorizontalScrollBar(), "grow, wrap");

    scrollPane.getHorizontalScrollBar().addAdjustmentListener(new AdjustmentListener() {
        @Override
        public void adjustmentValueChanged(final AdjustmentEvent e) {
            footerPane.getViewport().setViewPosition(new Point(e.getValue(), 0));
        }
    });

    egi.getColumnModel().addColumnModelListener(new TableColumnModelListener() {
        @Override
        public void columnAdded(final TableColumnModelEvent e) {
        }

        @Override
        public void columnMarginChanged(final ChangeEvent e) {
            final TableColumn column = egi.getTableHeader().getResizingColumn();
            if (column != null) {
                final JComponent totalsComponent = totalsComponents
                        .get(egi.convertColumnIndexToView(column.getModelIndex()));
                totalsComponent.setPreferredSize(new Dimension(column.getWidth(), totalsComponent.getHeight()));
                footer.revalidate();
            }
        }

        @Override
        public void columnMoved(final TableColumnModelEvent e) {
            final JComponent fromComponent = totalsComponents.get(e.getFromIndex());
            totalsComponents.set(e.getFromIndex(), totalsComponents.get(e.getToIndex()));
            totalsComponents.set(e.getToIndex(), fromComponent);

            footer.removeAll();
            for (int i = 0; i < egi.getColumnCount(); i++) {
                footer.add(totalsComponents.get(i), "grow, gap 0 0 0 0");
            }
            footer.revalidate();
        }

        @Override
        public void columnRemoved(final TableColumnModelEvent e) {
        }

        @Override
        public void columnSelectionChanged(final ListSelectionEvent e) {
        }
    });
    //
    //   return panel;
}