Scroll Pane does not work with shell menu [message #722478] |
Mon, 05 September 2011 18:50  |
Eclipse User |
|
|
|
Hi,
I have a simple class below where a shell with a menu bar is created and it contains a ScrollPane. The scroll pane content figure contains many rectangle figures which should cause the horizontal and vertical scroll bar to appear in the scroll pane. However the horizontal scroll bar does not appear when shell has a menu. If shell menu is not attached (comment buildMenu(shell) ) then both the horizontal and vertical scroll bars appear.
Anyone has any ideas on how this can be fixed?
Thanks,
Rahul
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.GridLayout;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.LightweightSystem;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.ScrollPane;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
public class ScrollPaneTest {
private static final int COLUMN_COUNT = 50;
private static final int FIGURE_COUNT = 500;
public static void main(String args[]) {
new ScrollPaneTest().process();
}
public void process() {
Display d = Display.getDefault();
final Shell shell = new Shell(d);
// Comment this line for the scroll bars
buildMenu(shell);
LightweightSystem lws = new LightweightSystem(shell);
final ScrollPane scrollPane = new ScrollPane();
lws.setContents(scrollPane);
final Figure contents = new Figure();
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = COLUMN_COUNT;
contents.setLayoutManager(gridLayout);
scrollPane.setContents(contents);
for (int i = 0; i < FIGURE_COUNT; i++) {
IFigure rectangleFigure = createFigure();
contents.add(rectangleFigure);
}
shell.open();
shell.setText("Example");
Display display = Display.getDefault();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
IFigure createFigure() {
RectangleFigure rectangleFigure = new RectangleFigure();
rectangleFigure.setBackgroundColor(ColorConstants.darkBlue);
rectangleFigure.setSize(300, 300);
return rectangleFigure;
}
private void buildMenu(final Shell shell) {
Menu menuBar = new Menu(shell, SWT.BAR);
shell.setMenuBar(menuBar);
MenuItem fileItem = new MenuItem(menuBar, SWT.CASCADE);
fileItem.setText("&File");
Menu fileSubmenu = new Menu(shell, SWT.DROP_DOWN);
fileItem.setMenu(fileSubmenu);
MenuItem exitMenuItem = new MenuItem(fileSubmenu, SWT.PUSH);
exitMenuItem.setText("E&xit");
exitMenuItem.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
shell.close();
}
});
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.03385 seconds