[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[platform-swt-dev] is it a bug of jface toolBar?
|
hello ,all,
I encounter a strange problem in window.
when I put a toolItem with a drop down menu and
a ToolItem with a image together into the toolBarManager of a jface
application,
and I find the former is enlarged by the height of the image of the later.
This is the snippt below:
import org.eclipse.jface.action.ContributionItem;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
public class MyApplicationWindow extends ApplicationWindow {
public MyApplicationWindow() {
super(null);
addToolBar(SWT.FLAT);
}
protected ToolBarManager createToolBarManager(int style) {
// Create the toolbar manager
ToolBarManager toolBarManager = new ToolBarManager(style);
toolBarManager.add(new ContributionItem() {
public void fill(final ToolBar toolBar, int index) {
final Menu menu = new Menu (toolBar.getShell(), SWT.POP_UP);
for (int i=0; i<8; i++) {
MenuItem item = new MenuItem (menu, SWT.PUSH);
item.setText ("Item " + i);
}
final ToolItem item = new ToolItem (toolBar, SWT.DROP_DOWN);
item.setText("Item");
item.addListener (SWT.Selection, new Listener () {
public void handleEvent (Event event) {
if (event.detail == SWT.ARROW) {
Rectangle rect = item.getBounds ();
Point pt = new Point (rect.x, rect.y + rect.height);
pt = toolBar.toDisplay (pt);
menu.setLocation (pt.x, pt.y);
menu.setVisible (true);
}
}
});
}
});
toolBarManager.add(new ContributionItem() {
public void fill(ToolBar toolBar, int index) {
ToolItem item = new ToolItem(toolBar,SWT.FLAT);
Image image = new
Image(toolBar.getDisplay(),"D:\\IBM\\virgoFTP\\icons\\refresh.gif");
item.setImage(image);
}
});
return toolBarManager;
}
public static void main(String[] args) {
MyApplicationWindow window = new MyApplicationWindow();
// Don't return from open() until window closes
window.setBlockOnOpen(true);
// Open the main window
window.open();
// Dispose the display
Display.getCurrent().dispose();
}
}
Thank you for your advice !