Java Code Examples for javax.swing.JTable#addPropertyChangeListener()

The following examples show how to use javax.swing.JTable#addPropertyChangeListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RowNumberTable.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Constructor to create a new {@link RowNumberTable} instance.
 *
 * @param contentTable
 *            the table the {@link RowNumberTable} should be created for
 */
public RowNumberTable(final JTable contentTable) {
	this.contentTable = contentTable;
	contentTable.addPropertyChangeListener(listener);

	setFocusable(false);
	setAutoCreateColumnsFromModel(false);

	TableColumn column = new TableColumn();
	column.setCellRenderer(new RowNumberRenderer());
	addColumn(column);

	// calculate preferred width dynamically
	int rowCount = contentTable.getRowCount();
	preferredWidth = 25;
	if (rowCount > 0) {
		preferredWidth = 15 + 6 * String.valueOf(rowCount).length();
	}
	getColumnModel().getColumn(0).setPreferredWidth(preferredWidth);
	setPreferredScrollableViewportSize(getPreferredSize());
}
 
Example 2
Source File: TableColumnManager.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
/**
    *  Create a TableColumnManager for a table.
    *
    *  @param table the table whose TableColumns will managed.
    *  @param menuPopup enable or disable a popup menu to allow the users to
    *                   manager the visibility of TableColumns.
    */
public TableColumnManager(JTable table, boolean menuPopup)
{
	this.table = table;
	setMenuPopup( menuPopup );

	table.addPropertyChangeListener( this );
	reset();
}
 
Example 3
Source File: ImprovedFileChooser.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public ImprovedFileChooser(File currentDirectory, FileSystemView fsv) {
  super(currentDirectory, fsv);

  AbstractButton detailsViewButton = getDetailsViewButton(this);
  if (detailsViewButton == null) {
    // mac osx does not have a details button. It is recommended to use
    // a java.awt.FileDialog box on MacOSX for the proper look and feel.
    // so, don't warn if on a mac.
    // https://developer.apple.com/library/mac/documentation/Java/Conceptual/Java14Development/07-NativePlatformIntegration/NativePlatformIntegration.html
    if (!isMacOs) {
      logger.warn("Couldn't find Details button!");
    }
    return;
  }

  detailsViewButton.doClick(); // Programmatically switch to the Details View.

  List<JTable> tables = SwingUtils.getDescendantsOfType(JTable.class, this);
  JTable detailsTable;

  if (tables.size() != 1) {
    logger.warn("Expected to find 1 JTable in the file chooser, but found " + tables.size());
    return;
  } else if ((detailsTable = tables.get(0)) == null) {
    logger.warn("The details view table was null!");
    return;
  }

  // Set the preferred column widths so that they're big enough to display all data without truncation.
  ColumnWidthsResizer resizer = new ColumnWidthsResizer(detailsTable);
  detailsTable.getModel().addTableModelListener(resizer);
  detailsTable.getColumnModel().addColumnModelListener(resizer);

  // Left-align every cell, including header cells.
  TableAligner aligner = new TableAligner(detailsTable, SwingConstants.LEADING);
  detailsTable.getColumnModel().addColumnModelListener(aligner);

  // Every time the directory is changed in a JFileChooser dialog, a new TableColumnModel is created.
  // This is bad, because it discards the alignment decorators that we installed on the old model.
  // So, we 're going to listen for the creation of new TableColumnModels so that we can reinstall the decorators.
  detailsTable.addPropertyChangeListener(new NewColumnModelListener(detailsTable, SwingConstants.LEADING));

  // It's quite likely that the total width of the table is NOT EQUAL to the sum of the preferred column widths
  // that our TableModelListener calculated. In that case, resize all of the columns an equal percentage.
  // This will ensure that the relative ratios of the *actual* widths match those of the *preferred* widths.
  detailsTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
}
 
Example 4
Source File: TableEditorStopper.java    From beast-mcmc with GNU Lesser General Public License v2.1 4 votes vote down vote up
private TableEditorStopper(JTable table)
{
    this.table=table;
    table.addPropertyChangeListener("tableCellEditor", this);
}
 
Example 5
Source File: SeaGlassTableUI.java    From seaglass with Apache License 2.0 3 votes vote down vote up
/**
 * Adds striping to the background of the given {@link JTable}. The actual
 * striping is installed on the containing {@link JScrollPane}'s
 * {@link JViewport}, so if this table is not added to a {@code JScrollPane}
 * , then no stripes will be painted. This method can be called before the
 * given table is added to a scroll pane, though, as a
 * {@link PropertyChangeListener} will be installed to handle "ancestor"
 * changes.
 *
 * @param table the table to paint row stripes for.
 */
public static void setViewPortListeners(JTable table) {
    table.addPropertyChangeListener("ancestor", createAncestorPropertyChangeListener(table));
    // Install a listener to cause the whole table to repaint when a column
    // is resized. We do this because the extended grid lines may need to be
    // repainted. This could be cleaned up, but for now, it works fine.
    for (int i = 0; i < table.getColumnModel().getColumnCount(); i++) {
        table.getColumnModel().getColumn(i).addPropertyChangeListener(createAncestorPropertyChangeListener(table));
        table.getColumnModel().addColumnModelListener(createTableColumnModelListener(table));
    }
}
 
Example 6
Source File: TableHelper.java    From CodenameOne with GNU General Public License v2.0 votes vote down vote up
public static PropertyChangeListener addModelTracker(JTable p_Table,
      final TableModelListener p_Listener) {
    PropertyChangeListener propListener = new PropertyChangeListener() {
      public void propertyChange(PropertyChangeEvent event) {
        TableModel oldModel = (TableModel) event.getOldValue();
        TableModel newModel = (TableModel) event.getNewValue();
        if (oldModel != null)
          oldModel.removeTableModelListener(p_Listener);
        if (newModel != null)
          newModel.addTableModelListener(p_Listener);
      }
    };
    p_Table.addPropertyChangeListener("model", propListener);
    p_Table.getModel().addTableModelListener(p_Listener);
    return propListener;
  } 
Example 7
Source File: TableHelper.java    From CodenameOne with GNU General Public License v2.0 votes vote down vote up
public static PropertyChangeListener addColumnModelTracker(JTable p_Table,
      final TableColumnModelListener p_Listener) {
    PropertyChangeListener propListener = new PropertyChangeListener() {
      public void propertyChange(PropertyChangeEvent event) {
        TableColumnModel oldModel = (TableColumnModel) event.getOldValue();
        TableColumnModel newModel = (TableColumnModel) event.getNewValue();
        if (oldModel != null)
          oldModel.removeColumnModelListener(p_Listener);
        if (newModel != null)
          newModel.addColumnModelListener(p_Listener);
      }
    };
    p_Table.addPropertyChangeListener("columnModel", propListener);
    p_Table.getColumnModel().addColumnModelListener(p_Listener);
    return propListener;
  }