Class UI

java.lang.Object
org.moeaframework.util.mvc.UI

public class UI extends Object
Utilities for creating UIs in a consistent manner. For best results, the constructor of the window should be called within show(Supplier) or showAndWait(Supplier). Within the constructor:
  1. Set the window title.
  2. Layout all components.
  3. Set Component.setPreferredSize(java.awt.Dimension)

OS-Specific Details

  • Mac (Darwin) - Call java with -Xdock:name=... to set the application title. Otherwise, the class name will appear in the title bar.
  • Method Details

    • setUseScreenMenuBar

      public static void setUseScreenMenuBar(boolean value)
      Optionally configure all windows to display their menu in Mac's system menu instead of within the window itself. This has no effect and is safe to call on other operating systems.

      Must be called before displaying any UI components!

      Parameters:
      value - if true, place menus in the system menu
    • configureLookAndFeel

      public static void configureLookAndFeel()
      Configures the system look and feel.

      Must be called before displaying any UI components! Note that it is not necessary to call this method explicitly so long as you are displaying windows using the methods in this class, since this method is called automatically when this class is first loaded.

    • show

      public static <T extends Window> CompletableFuture<T> show(Supplier<T> supplier)
      Creates a window asynchronously, scheduling the window to be created and displayed on the event dispatch thread. The returned future can be used to await this task, blocking until the window is displayed. If invoked from the event dispatch thread, the window is created immediately. Any exceptions will be thrown by the future wrapped in an ExecutionException.
      Type Parameters:
      T - the type of window
      Parameters:
      supplier - a function that creates the window
      Returns:
      the future used to access the displayed window
    • showAndWait

      public static <T extends Window> T showAndWait(Supplier<T> supplier)
      Creates a window synchronously.
      Type Parameters:
      T - the type of window
      Parameters:
      supplier - a function that creates the window
      Returns:
      the window after it is displayed
    • clearEventQueue

      public static void clearEventQueue()
      Blocks until all events scheduled in the event queue are processed. This method no-ops if run from the event dispatch thread.
    • disposeAll

      public static void disposeAll()
      Disposes all dialogs and windows.