use of java.awt.event.HierarchyBoundsAdapter in project omegat by omegat-org.
the class TableColumnSizer method init.
/**
* Add various listeners to keep the columns in sync with the table's
* current width.
*/
private void init() {
table.getColumnModel().addColumnModelListener(colListener);
table.getModel().addTableModelListener(modelListener);
table.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
Object oldVal = evt.getOldValue();
Object newVal = evt.getNewValue();
if (newVal != null && newVal.equals(evt.getOldValue())) {
return;
}
boolean shouldAdjust = false;
if (evt.getPropertyName().equals("columnModel")) {
if (newVal != null && newVal instanceof TableColumnModel) {
((TableColumnModel) newVal).addColumnModelListener(colListener);
shouldAdjust = true;
}
if (oldVal != null && oldVal instanceof TableColumnModel) {
((TableColumnModel) oldVal).removeColumnModelListener(colListener);
}
} else if (evt.getPropertyName().equals("model")) {
if (newVal != null && newVal instanceof TableModel) {
((TableModel) newVal).addTableModelListener(modelListener);
shouldAdjust = true;
}
if (oldVal != null && oldVal instanceof TableModel) {
((TableModel) oldVal).removeTableModelListener(modelListener);
}
} else if (evt.getPropertyName().equals("font")) {
if ((newVal != null && !newVal.equals(oldVal)) || (oldVal != null && !oldVal.equals(newVal))) {
shouldAdjust = true;
}
}
if (shouldAdjust) {
reset();
// Queue up the adjustment because when the table has a
// RowSorter things can be out of sync at this point.
SwingUtilities.invokeLater(TableColumnSizer.this::adjustTableColumns);
}
}
});
table.addHierarchyBoundsListener(new HierarchyBoundsAdapter() {
@Override
public void ancestorResized(HierarchyEvent e) {
adjustTableColumns();
}
});
}
Aggregations