-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
71 lines (65 loc) · 3.3 KB
/
Main.java
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
62
63
64
65
66
67
68
69
70
71
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import javax.swing.tree.TreePath;
import org.jdesktop.swingx.treetable.AbstractMutableTreeTableNode;
import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode;
import org.jdesktop.swingx.treetable.DefaultTreeTableModel;
public class Main {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable(){
@Override
public void run() {
final MyTreeTable treeTable = new MyTreeTable();
treeTable.setTreeTableModel(new DefaultTreeTableModel(new DefaultMutableTreeTableNode("root")));
JButton button = new JButton("Add nodes");
button.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
DefaultTreeTableModel model = (DefaultTreeTableModel)treeTable.getTreeTableModel();
DefaultMutableTreeTableNode parentNode = null;
TreePath parentPath = treeTable.getTreeSelectionModel().getSelectionPath();
if (parentPath == null) {
parentNode = (DefaultMutableTreeTableNode) model.getRoot();
} else {
parentNode = (DefaultMutableTreeTableNode) (parentPath.getLastPathComponent());
}
model.insertNodeInto(new DefaultMutableTreeTableNode("Aname"+System.currentTimeMillis()), parentNode, parentNode.getChildCount());
treeTable.expandAll();
}
});
final JTextField filterText = new JTextField();
filterText.addCaretListener(new CaretListener(){
@Override
public void caretUpdate(CaretEvent e) {
if (filterText.getText().length() > 0) {
treeTable.setModelFilter(new TellapicModelFilter(treeTable){
@Override
public boolean shouldBeFiltered(AbstractMutableTreeTableNode node) {
return node.getUserObject().toString().toLowerCase().startsWith(filterText.getText().toLowerCase());
}
});
} else {
treeTable.setModelFilter(null);
}
}
});
JFrame frame = new JFrame("Filter test");
frame.getContentPane().add(treeTable, BorderLayout.CENTER);
frame.getContentPane().add(filterText, BorderLayout.NORTH);
frame.getContentPane().add(button, BorderLayout.SOUTH);
frame.setPreferredSize(new Dimension(800, 600));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
});
}
}