1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| public class IFMTreeTable extends JTreeTable {
private static final long serialVersionUID = 1L;
public IFMTreeTable(TreeTableModel treeTableModel) {
super(treeTableModel);
setShowGrid(true);
setGridColor(new Color(234, 234, 234));
setIntercellSpacing(new Dimension(1, 1));
//setIntercellSpacing(new Dimension(0, 0));
JTree tree = (JTree) getDefaultRenderer(TreeTableModel.class);
//tree.setRootVisible(true);
tree.setAutoscrolls(false);
tree.setDoubleBuffered(true);
tree.setCellRenderer(new IFMTreeTableCellRenderer());
tree.setLargeModel(true);
tree.setName("IFMTree");
tree.setScrollsOnExpand(true);
new TableColumnResizer(this);
}
public boolean editCellAt(int row, int column, EventObject e) {
if (e instanceof MouseEvent) {
MouseEvent me = (MouseEvent) e;
// If the modifiers are not 0 (or the left mouse button),
// tree may try and toggle the selection, and table
// will then try and toggle, resulting in the
// selection remaining the same. To avoid this, we
// only dispatch when the modifiers are 0 (or the left mouse
// button).
if (me.getModifiers() == 0 || me.getModifiers() == InputEvent.BUTTON1_MASK) {
for (int counter = getColumnCount() - 1; counter >= 0; counter--) {
if (getColumnClass(counter) == TreeTableModel.class) {
MouseEvent newME = new MouseEvent(tree, me.getID(), me.getWhen(), me.getModifiers(),
me.getX() - getCellRect(0, counter, true).x, me.getY(), me.getClickCount(), me.isPopupTrigger());
tree.dispatchEvent(newME);
break;
}
}
}
return false;
}
return super.editCellAt(row, column, e);
}
// mouse press intended for resize shouldn't change row/col/cell celection
public void changeSelection(int row, int column, boolean toggle, boolean extend) {
if (getCursor() == TableColumnResizer.resizeCursor) {
return;
}
super.changeSelection(row, column, toggle, extend);
}
// overriden to make the height of scroll match viewpost height if smaller
public boolean getScrollableTracksViewportHeight() {
return getPreferredSize().height < getParent().getHeight();
}
} |
Partager