6.2.3. Verwendung der nativen UI Referenz unter Swing

Das JoToSwingSnipped demonstriert die Verwendung der nativen Swing UI Referenz in einer jowidgets Applikation:

  1  package org.jowidgets.examples.swing.snipped;
  2  
  3  import java.awt.BorderLayout;
  4  
  5  import javax.swing.JPanel;
  6  import javax.swing.JTextPane;
  7  import javax.swing.UIManager;
  8  
  9  import org.jowidgets.api.layout.FillLayout;
 10  import org.jowidgets.api.toolkit.Toolkit;
 11  import org.jowidgets.api.widgets.IComposite;
 12  import org.jowidgets.api.widgets.IFrame;
 13  import org.jowidgets.common.application.IApplication;
 14  import org.jowidgets.common.application.IApplicationLifecycle;
 15  import org.jowidgets.tools.widgets.blueprint.BPF;
 16  
 17  public final class JoToSwingSnipped implements IApplication {
 18  
 19      @Override
 20      public void start(final IApplicationLifecycle lifecycle) {
 21          //create the root frame
 22          final IFrame frame = Toolkit.createRootFrame(BPF.frame("JoToSwing Snipped"), lifecycle);
 23          frame.setSize(800, 600);
 24          frame.setLayout(FillLayout.get());
 25  
 26          //create a regular jo composite
 27          final IComposite joComposite = frame.add(BPF.composite());
 28  
 29          //get the native ui reference which must be a JPanel
 30          //because swing SPI impl is used
 31          final JPanel panel = (JPanel) joComposite.getUiReference();
 32          panel.setLayout(new BorderLayout());
 33  
 34          //create a JTextPane and add it to the panel
 35          final JTextPane textPane = new JTextPane();
 36          panel.add(textPane);
 37  
 38          //set the root frame visible
 39          frame.setVisible(true);
 40      }
 41  
 42      public static void main(final String[] args) throws Exception {
 43          UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
 44          System.setProperty("apple.laf.useScreenMenuBar", "true");
 45          Toolkit.getApplicationRunner().run(new JoToSwingSnipped());
 46          System.exit(0);
 47      }
 48  }

Siehe auch PDF Version dieses Dokuments, Jowidgets API Spezifikation