1 year ago
#352586
Vt0613
How can I perform a single selection on dynamically generated tree items?
I need to perform the following task: On selection of a single tree item in a treeViewer, relevant data is supposed to display in the tableViewer. I have retrieved data from MySQL, using the rs.getString() method, and added the obtained string array into the tree item using the setText() method. I need to select one of the string values displayed in the treeViewer that has been dynamically generated.
On using a selection event for the tree, all generated elements get selected. How can I obtain a single selection? Is there any method similar to getSelectedItem() for a treeViewer? This is the code i used to generate the tree items:
Tree tree_1 = treeViewer.getTree();
tree_1.setBounds(316, 205, 244, 446);
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con2 = DriverManager.getConnection("jdbc:mysql://localhost:3306/project","xxxx","xxxx");
Statement stmt2 = con2.createStatement();
String query2="select DISTINCT xxx FROM xxxxx";
ResultSet rs2=stmt2.executeQuery(query2);
while(rs2.next()) {
String executive=rs2.getString("xxxx");
TreeItem item4=new TreeItem(tree_1,SWT.NONE);
item4.setText(executive);
item4.setFont(SWTResourceManager.getFont("Times New Roman", 12, SWT.NORMAL));
}
}
java
eclipse
eclipse-rcp
jface
0 Answers
Your Answer