Reputation: 39
Currently I have small bug when using TreeEditor. My code:
package test;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.TreeEditor;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.swt.widgets.TreeItem;
public class Test {
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
Tree tree = new Tree(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
tree.setHeaderVisible(true);
TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
column1.setText("Column 1");
column1.setWidth(200);
TreeColumn column2 = new TreeColumn(tree, SWT.CENTER);
column2.setText("Column 2");
column2.setWidth(200);
TreeColumn column3 = new TreeColumn(tree, SWT.RIGHT);
column3.setText("Column 3");
column3.setWidth(200);
TreeColumn column4 = new TreeColumn(tree, SWT.LEFT);
column4.setText("Column 4");
column4.setWidth(200);
for (int i = 0; i < 20; i++) {
TreeItem item = new TreeItem(tree, SWT.NONE);
item.setText(new String[] { "item " + i, "abc" + i, "percentage " + i });
ProgressBar bar = new ProgressBar(tree, SWT.NULL);
bar.setVisible(true);
bar.setSelection(i);
bar.setToolTipText(i + "%");
TreeEditor editor = new TreeEditor(tree);
editor.grabHorizontal = true;
editor.grabVertical = true;
editor.setEditor(bar, item, 3);
}
// shell.pack();
shell.setSize(900, 295);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
When I click the text of bottom row ("item 12"), OS will scroll down 1 row automatically. But when I check ProgressBar ToolTip, "item 12" progress bar shows 11%. It mean that progress bar is not scrolled down one row. How can I resolve this problem? Thank you.
Upvotes: 1
Views: 86
Reputation: 2360
Looks like a bug to me that the entire column (when setup using a ControlEditor
) does not auto-scroll along with the others. Bugs can be reported over here: Eclipse Bugzilla.
It doesn't seem to be the ProgressBar
that's the issue. If you replace it with a Label
, for example, you'll have the same problem.
One possible workaround that seems to work would be to call the setSelection(TreeItem[])
method in a listener. That seems to get the column to correct itself.
For example:
tree.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
tree.setSelection(tree.getSelection());
}
});
Getting the selected TreeItem
s and then setting them right back should be fairly innocuous as long as your application doesn't do anything special around SelectionEvent
s on the Tree
.
Upvotes: 1