1 package wjhk.jupload2.gui.filepanel.treeview;
2
3 import java.awt.Component;
4 import java.awt.Graphics;
5
6 import javax.swing.JTable;
7 import javax.swing.JTree;
8 import javax.swing.table.TableCellRenderer;
9 import javax.swing.tree.TreeModel;
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 public class MyTreeTableCellRenderer extends JTree implements TableCellRenderer {
27
28 private static final long serialVersionUID = 1L;
29
30
31 protected int visibleRow;
32
33 private MyTreeTable treeTable;
34
35 public MyTreeTableCellRenderer(MyTreeTable treeTable, TreeModel model) {
36 super(model);
37 this.treeTable = treeTable;
38
39
40
41
42 setRowHeight(getRowHeight());
43
44 setRootVisible(false);
45 setScrollsOnExpand(true);
46 setShowsRootHandles(true);
47 }
48
49
50
51
52 public void setRowHeight(int rowHeight) {
53 if (rowHeight > 0) {
54 super.setRowHeight(rowHeight);
55 if (treeTable != null && treeTable.getRowHeight() != rowHeight) {
56 treeTable.setRowHeight(getRowHeight());
57 }
58 }
59 }
60
61
62
63
64 public void setBounds(int x, int y, int w, int h) {
65 super.setBounds(x, 0, w, treeTable.getHeight());
66 }
67
68
69
70
71 public void paint(Graphics g) {
72 g.translate(0, -visibleRow * getRowHeight());
73
74 super.paint(g);
75 }
76
77
78
79
80 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
81 int row, int column) {
82 if (isSelected)
83 setBackground(table.getSelectionBackground());
84 else
85 setBackground(table.getBackground());
86
87 visibleRow = row;
88 return this;
89 }
90 }