Skip to main content
Jump to: navigation, search


< SWT‎ | Devel‎ | Gtk

About SWT PI development

PI as in aPI means Program Interface.

This is a means to write java code that makes native C Gtk calls. This is particularly useful for testing GTK code without the entire SWT framework running concurrently.

An example snippet would be:
  public class Snippet1 {
  public static void main (String [] args) {
    OS.gtk_init_check(new long[0], new long[0]);
      /* create a new window */
      long window = OS.gtk_window_new(OS.GTK_WINDOW_TOPLEVEL);
      OS.gtk_window_set_title(window, OS.ascii("GTK Menu Test"));
      long menu = OS.gtk_menu_new();
      long root_menu = OS.gtk_image_menu_item_new_with_label(OS.ascii("Root Menu"));
      for(int i = 0; i < 3; i++) {
        String buf = "Test-undermenu -" + i;
        long menu_items = OS.gtk_image_menu_item_new_with_label(OS.ascii(buf));
        OS.gtk_menu_shell_insert(menu, menu_items, i);
      /* Now we specify that we want our newly created "menu" to be the menu for the "root menu" */
      OS.gtk_menu_item_set_submenu(root_menu, menu);
      /* Create a menu-bar to hold the menus and add it to our main window*/
      long menu_bar = OS.gtk_menu_bar_new();
      OS.gtk_container_add(window, menu_bar);
      OS.gtk_menu_shell_insert(menu_bar, root_menu, 0);
      OS.gtk_main ();

Back to the top