com.javonet.api

Class NControlJContainer

  • java.lang.Object
    • java.awt.Component
      • java.awt.Container
        • javax.swing.JComponent
          • javax.swing.JPanel
            • com.javonet.api.NControlJContainer
  • All Implemented Interfaces:
    java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

    public class NControlJContainer
    extends javax.swing.JPanel
    A class that is used to embed .NET UI components in Swing window or UI elements.

    This class is an wrapper over standard NControlContainer that can be used for AWT, Swing and JavaFx.
    This class is used to resolve the issues of mixing .NET heavyweight components with Swing lightweight design.
    Any issues related to mixing HW with LW components in Java are resolved using this container.

    Use this class to wrap the NObject instance holding the reference to .NET WinForms or WPF user control.

    You can add any .NET WPF or WinForms user control to JAVA user interface. NControlContainer class
    will take care of embedding and integrating .NET UI components with JAVA and bind the window events
    like resizing, minimizing, maximizing, moving or closing. .NET UI components transparently for end-user
    lives within Java user interface added to grid, panel or window with size being adjusted either automatically
    by layout or set to fixed values on NControlJContainer class.

    NControlJContainer class derives from java.awt.JPanel and offers the same functionality as Java panel control.

    Usage

    To embed .NET WinForms or WPF user control in Java user interface you must add reference to .NET DLL file which contains
    the implementation of .NET UI component, initialize the instance of .NET user control and store it in NObject variable.
    Finally initialize the NControlJContainer class passing .NET user control stored in NObject as argument to
    NControlJContainer constructor.

    Control wrapped in NControlJContainer class can be added to JAVA Swing interface like in the code
    sample below:

     
     Javonet.addReference("Javonet.WinFormsUserControlSample.dll");
     NObject userControl = Javonet.New("Javonet.WinFormsUserControlSample.UserControl1");
     NControlJContainer wuc = new NControlJContainer(userControl);
     
     Frame guiFrame = new Frame();
     guiFrame.add(wuc, BorderLayout.CENTER);
     

    Interaction with user control and events handling

    You can easily interact with .NET user control stored in NControlJContainer class. Because .NET user control is wrapped
    by the container class, to interact with its content you should use either the instance of NObject passed to NControlJContainer constructor
    or get the wrapped class using getUserControl() method.

    With user control you can interact in the same way as with any .NET class stored in NObject. Therefore you can bind events, invoke methods
    get / set fields and properties and modify the user control appearance.

    Sample below show how to bind to Click event:

      
     (...)
     NControlJContainer wuc = new NControlJContainer(userControl);
     
     wuc.addEventListener("ButtonClicked", new NEventListener() {
     	public void eventOccurred(Object[] arguments) {
     		//custom event handling code that will be called when button on .NET user 
    		//control is clicked
    
     		//ButtonClicked event subscribed has been exposed in the user control class 
     		//implementation on .NET side (in this particular example)
    			
     		//arguments[0] of button click events send from .NET usually contains value of 
     		//"object sender" argument therefore it gives access to the instance of event source control
     	}
     });
     
     
    Since:
    1.5
    Author:
    Javonet
    See Also:
    Serialized Form


    • Nested Class Summary



      • Nested classes/interfaces inherited from class javax.swing.JComponent

        javax.swing.JComponent.AccessibleJComponent



      • Nested classes/interfaces inherited from class java.awt.Component

        java.awt.Component.BaselineResizeBehavior



    • Field Summary



      • Fields inherited from class javax.swing.JComponent

        TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW



      • Fields inherited from class java.awt.Component

        BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT



      • Fields inherited from interface java.awt.image.ImageObserver

        ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH



    • Constructor Summary

      Constructors 
      Constructor and Description
      NControlJContainer(NObject control)

      Creates instance of NControlJContainer with particular instance of .NET user control.



    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      NObject getUserControl()

      Returns the NObject instance of .NET user control being wrapped by this
      NControlJContainer.
      void paint(java.awt.Graphics g) 
      void requestFocus() 


      • Methods inherited from class javax.swing.JPanel

        getAccessibleContext, getUI, getUIClassID, setUI, updateUI



      • Methods inherited from class javax.swing.JComponent

        addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update



      • Methods inherited from class java.awt.Container

        add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate



      • Methods inherited from class java.awt.Component

        action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle



      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait



    • Constructor Detail



      • NControlJContainer

        public NControlJContainer(NObject control)
                           throws JavonetException
        Creates instance of NControlJContainer with particular instance of .NET user control.
        Parameters:
        control – NObject instance associated with .NET WPF or WinForms user control.
        Throws:
        JavonetException – exception thrown in case of Javonet issues while initializing the container.



    • Method Detail



      • getUserControl

        public NObject getUserControl()
        Returns the NObject instance of .NET user control being wrapped by this
        NControlJContainer. You can use this method to access the underlying control
        to bind events, get/set fields, invoke methods or modify the appearance of
        the user control.
        Returns:
        NObject of userControl being wrapped by this instance of NControlJContainer



      • paint

        public void paint(java.awt.Graphics g)
        Overrides:
        paint in class javax.swing.JComponent



      • requestFocus

        public void requestFocus()
        Overrides:
        requestFocus in class javax.swing.JComponent