Problem when including combo boxes as subitems in multi column tree. [message #491459] |
Wed, 14 October 2009 16:35 |
No real name Messages: 2 Registered: October 2009 |
Junior Member |
|
|
Hi,
I am trying to create a multi column tree with combos in some sub items.
This actually works fine except that a combo in addition appears at the upper left corner of the tree.
The problem only appears with combo boxes, NOT with other SWT widgets.
Any idea why this happens ?
(I use Windows Pro and Eclipse 3.4)
Find the code below.
Thanks,
Thomas
import java.util.Arrays;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.TreeEditor;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
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 MultiColumnTreeWithCombo {
public static void main(String[] args) {
final int SOU = 0;
final int PIF = 1;
final int DAE = 2;
final int SSI = 3;
Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
Tree map = new Tree(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
map.addListener(SWT.MeasureItem, new Listener() {
public void handleEvent(Event event) {
// sets the height of the entire row to fit the control
event.height = 25;
}
});
map.setHeaderVisible(true);
map.setLinesVisible(true);
for (int a=0;a<4;a++)
{
TreeColumn column = new TreeColumn(map, SWT.LEFT);
column.setText("Column"+a);
column.pack();
}
for(int i = 0; i<5; i++)
{
TreeItem tItem = new TreeItem (map, SWT.NONE);
tItem.setText (SOU, "item1_"+i);
tItem.setText (PIF, "item2_"+i);
for(int k = 0; k<3; k++)
{
TreeItem subItem = new TreeItem(tItem, SWT.NONE);
subItem.setText(DAE,("item3_" + k));
Combo sSignalCombo = new Combo(map, SWT.NONE);
for(int z = 0; z<3; z++)
{
sSignalCombo.add("item4_" + z);
}
String[] ssItems = sSignalCombo.getItems();
Arrays.sort(ssItems);
sSignalCombo.setItems(ssItems);
sSignalCombo.computeSize(SWT.DEFAULT, map.getItemHeight());
sSignalCombo.pack();
TreeEditor ssEditor = new TreeEditor(map);
ssEditor.minimumWidth = sSignalCombo.getSize().x;
ssEditor.grabHorizontal = true;
ssEditor.setEditor(sSignalCombo, subItem, SSI);
}
}
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
|
|
|
Re: Problem when including combo boxes as subitems in multi column tree. [message #491941 is a reply to message #491459] |
Fri, 16 October 2009 15:42 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
Removing the "sSignalCombo.pack();" fixes this for me. Also, the
computeSize() line above it can go away since you aren't using its return
value for anything.
Grant
<thomas_wuerz@mentor.com> wrote in message
news:hb4ul8$ku8$1@build.eclipse.org...
> Hi,
> I am trying to create a multi column tree with combos in some sub items.
> This actually works fine except that a combo in addition appears at the
upper left corner of the tree.
> The problem only appears with combo boxes, NOT with other SWT widgets.
> Any idea why this happens ?
> (I use Windows Pro and Eclipse 3.4)
>
> Find the code below.
> Thanks,
> Thomas
>
> import java.util.Arrays;
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.custom.TreeEditor;
> import org.eclipse.swt.layout.FillLayout;
> import org.eclipse.swt.widgets.Combo;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Event;
> import org.eclipse.swt.widgets.Listener;
> 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 MultiColumnTreeWithCombo {
> public static void main(String[] args) {
> final int SOU = 0;
> final int PIF = 1;
> final int DAE = 2;
> final int SSI = 3;
>
> Display display = new Display();
> final Shell shell = new Shell(display);
> shell.setLayout(new FillLayout());
> Tree map = new Tree(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
>
> map.addListener(SWT.MeasureItem, new Listener() {
> public void handleEvent(Event event) {
> // sets the height of the entire row to fit the control
> event.height = 25;
> }
> });
>
> map.setHeaderVisible(true);
> map.setLinesVisible(true);
>
> for (int a=0;a<4;a++)
> {
> TreeColumn column = new TreeColumn(map, SWT.LEFT);
> column.setText("Column"+a);
> column.pack();
> }
>
> for(int i = 0; i<5; i++)
> {
> TreeItem tItem = new TreeItem (map, SWT.NONE);
> tItem.setText (SOU, "item1_"+i);
> tItem.setText (PIF, "item2_"+i);
>
>
> for(int k = 0; k<3; k++)
> {
>
> TreeItem subItem = new TreeItem(tItem, SWT.NONE);
> subItem.setText(DAE,("item3_" + k));
>
> Combo sSignalCombo = new Combo(map, SWT.NONE);
>
> for(int z = 0; z<3; z++)
> {
> sSignalCombo.add("item4_" + z);
> }
>
> String[] ssItems = sSignalCombo.getItems();
> Arrays.sort(ssItems);
> sSignalCombo.setItems(ssItems);
>
>
> sSignalCombo.computeSize(SWT.DEFAULT, map.getItemHeight());
> sSignalCombo.pack();
>
>
> TreeEditor ssEditor = new TreeEditor(map);
> ssEditor.minimumWidth = sSignalCombo.getSize().x;
> ssEditor.grabHorizontal = true;
> ssEditor.setEditor(sSignalCombo, subItem, SSI);
>
> }
> }
>
> shell.pack();
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch()) {
> display.sleep();
> }
> }
> display.dispose();
> }
> }
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.03225 seconds