Example usage for javax.swing.table JTableHeader getTable

List of usage examples for javax.swing.table JTableHeader getTable

Introduction

In this page you can find the example usage for javax.swing.table JTableHeader getTable.

Prototype

public JTable getTable() 

Source Link

Document

Returns the table associated with this header.

Usage

From source file:Main.java

public void mouseMoved(MouseEvent evt) {
    JTableHeader header = (JTableHeader) evt.getSource();
    JTable table = header.getTable();
    TableColumnModel colModel = table.getColumnModel();
    int vColIndex = colModel.getColumnIndexAtX(evt.getX());
    TableColumn col = null;//from  w  w  w. j av  a2 s  . c  o  m
    if (vColIndex >= 0) {
        col = colModel.getColumn(vColIndex);
    }
    if (col != curCol) {
        header.setToolTipText((String) tips.get(col));
        curCol = col;
    }
}

From source file:SortableTable.java

/**
 * When the user releases the mouse button, we attempt to sort the table.
 *
 * @param e  the mouse event./*from  w w w.ja  va 2s.c o  m*/
 */
public void mouseReleased(final MouseEvent e) {

    final JTableHeader header = (JTableHeader) e.getComponent();

    if (header.getResizingColumn() == null) { // resizing takes precedence over sorting
        if (this.sortColumnIndex != -1) {
            final SortableTableModel model = (SortableTableModel) header.getTable().getModel();
            final boolean ascending = !model.isAscending();
            model.setAscending(ascending);
            model.sortByColumn(this.sortColumnIndex, ascending);

            this.renderer.setPressedColumn(-1); // clear
            header.repaint();
        }
    }
}

From source file:SortableTable.java

/**
 * Handle a mouse press event - if the user is NOT resizing a column and NOT dragging a column
 * then give visual feedback that the column header has been pressed.
 *
 * @param e  the mouse event./*from   w  w  w.jav a2  s . c  o m*/
 */
public void mousePressed(final MouseEvent e) {

    final JTableHeader header = (JTableHeader) e.getComponent();

    if (header.getResizingColumn() == null) { // resizing takes precedence over sorting
        if (header.getDraggedDistance() < 1) { // dragging also takes precedence over sorting
            final int columnIndex = header.columnAtPoint(e.getPoint());
            final int modelColumnIndex = header.getTable().convertColumnIndexToModel(columnIndex);
            if (this.model.isSortable(modelColumnIndex)) {
                this.sortColumnIndex = header.getTable().convertColumnIndexToModel(columnIndex);
                this.renderer.setPressedColumn(this.sortColumnIndex);
                header.repaint();
                if (header.getTable().isEditing()) {
                    header.getTable().getCellEditor().stopCellEditing();
                }
            } else {
                this.sortColumnIndex = -1;
            }
        }
    }

}

From source file:org.yccheok.jstock.gui.PortfolioManagementJPanel.java

private void initGUIOptions() {
    File f = new File(org.yccheok.jstock.gui.Utils.getUserDataDirectory() + "config" + File.separator
            + "portfoliomanagementjpanel.xml");
    final GUIOptions guiOptions = Utils.fromXML(GUIOptions.class, f);

    if (guiOptions == null) {
        return;/*from   w w  w.j ava2  s  .  c o m*/
    }

    if (guiOptions.getJTableOptionsSize() <= 1) {
        return;
    }

    final org.jdesktop.swingx.JXTreeTable[] treeTables = { buyTreeTable, sellTreeTable };

    /* Set Table Settings */
    for (int tableIndex = 0; tableIndex < treeTables.length; tableIndex++) {
        final JXTreeTable treeTable = treeTables[tableIndex];
        final javax.swing.table.JTableHeader jTableHeader = treeTable.getTableHeader();
        final JTable jTable = jTableHeader.getTable();
        JTableUtilities.setJTableOptions(jTable, guiOptions.getJTableOptions(tableIndex));
    }

    // Do we have the divider location option?
    if (guiOptions.getDividerLocationSize() > 0) {
        // Yes. Remember the divider location.
        // It will be used in updateDividerLocation later.
        this.dividerLocation = guiOptions.getDividerLocation(0);
    }
}

From source file:org.yccheok.jstock.gui.PortfolioManagementJPanel.java

public boolean saveGUIOptions() {
    if (Utils.createCompleteDirectoryHierarchyIfDoesNotExist(
            org.yccheok.jstock.gui.Utils.getUserDataDirectory() + "config") == false) {
        return false;
    }/*www  .  j  a  va 2s.  co  m*/

    final GUIOptions guiOptions = new GUIOptions();

    final org.jdesktop.swingx.JXTreeTable[] treeTables = { buyTreeTable, sellTreeTable };

    for (org.jdesktop.swingx.JXTreeTable treeTable : treeTables) {
        final javax.swing.table.JTableHeader jTableHeader = treeTable.getTableHeader();
        final JTable jTable = jTableHeader.getTable();
        final GUIOptions.JTableOptions jTableOptions = new GUIOptions.JTableOptions();

        final int count = jTable.getColumnCount();
        for (int i = 0; i < count; i++) {
            final String name = jTable.getColumnName(i);
            final TableColumn column = jTable.getColumnModel().getColumn(i);
            jTableOptions.addColumnOption(
                    GUIOptions.JTableOptions.ColumnOption.newInstance(name, column.getWidth()));
        }

        guiOptions.addJTableOptions(jTableOptions);
    }

    guiOptions.addDividerLocation(jSplitPane1.getDividerLocation());

    File f = new File(org.yccheok.jstock.gui.Utils.getUserDataDirectory() + "config" + File.separator
            + "portfoliomanagementjpanel.xml");
    return org.yccheok.jstock.gui.Utils.toXML(guiOptions, f);
}