[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: Menu Bar height?

I think you can create a no_trim shell,  add the menu bar and menus. Then 
you can get the menu bar height as the following code shows.

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;

import com.swtdesigner.SWTResourceManager;

public class TestLink {
 public static void main(String[] args) {
  final Display display = new Display();
  final Shell shell = new Shell(display,SWT.NO_TRIM);
  shell.setBackground(SWTResourceManager.getColor(255, 0, 0));
  shell.setSize(138, 89);
  final Label label = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
  label.setBounds(415, 285, -30, -83);

  final Menu menu = new Menu(shell, SWT.BAR);
  shell.setMenuBar(menu);

  final MenuItem newSubmenuMenuItem = new MenuItem(menu, SWT.CASCADE);
  newSubmenuMenuItem.setText("New SubMenu");

  final Menu menu_1 = new Menu(newSubmenuMenuItem);
  newSubmenuMenuItem.setMenu(menu_1);

  final MenuItem newItemMenuItem = new MenuItem(menu_1, SWT.NONE);
  newItemMenuItem.setText("New Item");

  final Button button = new Button(shell, SWT.NONE);
  button.addSelectionListener(new SelectionAdapter() {
   public void widgetSelected(final SelectionEvent e) {
    System.out.println(menu.getShell().getClientArea());
    System.out.println(menu.getShell().getSize());
    System.out.println(menu.getShell().getSize().y - 
menu.getShell().getClientArea().height);
   }
  });
  button.setText("button");
  button.setBounds(85, 41, 48, 22);

  // ===========================
  shell.open();
  while (!shell.isDisposed()) {
   if (!display.readAndDispatch()) {
    display.sleep();
   }
  }
  display.dispose();
 }
}



"Andres C. Rodriguez" <acr@xxxxxxxxxx> 
??????:fvo8hu$oi0$1@xxxxxxxxxxxxxxxxxxxx
>
> Can someone tell me how to get the menu bar height for menus inside 
> Shells?  Thanks.
>
>
> ACR