UI delegate for a custom component

Hello folks,
I am trying to write (as said in the subject) a UI delegate for a custom component. I found the following in a Java FAQ (http://www.mindspring.com/~scdrye/java/faq.html#plaf_delegate):
8.3. How do I create a UI delegate for my custom component?
Have your component extend from JComponent (or a descendant of JComponent). Create a subclass of ComponentUI for your custom component, overriding at least the createUI() and paint() methods. To enable the new UI, override four methods of your JComponent subclass:
public class MyComponent extends JComponent {
public void updateUI() {
setUI((MyComponentUI)UIManager.getUI(this));
public void setUI(MyComponent newUI) {
super.setUI(newUI);
public MyComponentUI getUI() {
return (MyComponentUI)ui;
public String getUIClassID() {
return "MyComponentUI";
Well, it turns out that this is not enough. I also had to add during application start (just before initComponents()) the following:
UIManager.put(uiClassID, uiClassName);
to avoid exceptions during start of the program.
Well, now my component is painted (paintComponent()) is called, but the paint() method in my new UI delegate class is not called when the application starts.
It just gets called when I explicitily (in this case, using a menu item) change the L&F of the application.
If this informatio is not enough, I can add some excerpts of my code for the ease of understanding!!
Thanks a lot!

If I code a new custom component (extending JComponent, or extending the UI delegate of a standard component) and pretend it to be laf aware then I must create the corresponding UI delegate for each laf, like it happens to be with standard swing components. But I'm not sure it is feasible to create the UI delegates for all unknown existing custom lafs.You are right, this is never going to work. I suggest if you want to make your custom component look & feel aware, you design the way it displays around the l & f of other components that are part of j2se and have l&f implementations.
http://download.oracle.com/javase/7/docs/api/javax/swing/plaf/ComponentUI.html
There are instructions here:
http://download.oracle.com/javase/7/docs/api/javax/swing/LookAndFeel.html
>
On the other side, if I create a custom laf then I will also create a custom UI delegate for each standard component, but I can not create UI delegate for all unknown existing custom components.
The point here is that standard components and standard lafs are universally known, while custom components (or custom ui delegates) and custom lafs are not.
So the question is: How does a swing developer deal with the case of a new custom component that will be used in an unknown custom laf?
For instance:
1. Custom text UI delegate for dealing with styled documents in JTextField. See {thread:id=2284487}.
2. JTabbedPane with custom UI delegate that paints no tab if the component only contains one tab.
In both cases I need a UI delegate for each known laf, but what happens if the application is using a laf that certainly will not be aware of this custom functionally?
Thank you!

Similar Messages

  • Decode function not called for a custom component

    I know this problem happened in the past - in the EA2, EA4 and I believe the beta version as well, but does anyone know if it has been solved for the release ?
    In short - I'm working with the release, created a menuBar component and the decode method in the renderer is not called after I submit the page. In the past, there were rumors that this happened due to relative paths in the JSP (for js files, images, etc.).
    Does anyone else have this problem ? or better , know how to solve it ?
    Thanx,
    Netta.

    It's not that simple - The component is getting rendered, all the encode methods are called and the decode is called also , but only the first time the form is submitted.
    I added this custom component to the guessNumber application, and I have a menuBar in the greeting.jsp that leads to the response.jsp and vice versa. it looks like this in the greeting.jsp page -
    <!-- Start Menu -->
    <t:MenuBar id="bar1" styleClass="myClass" >
    <t:Menu id="menu1" name="menu1">
    <t:Menu id="menu2" name="menu2">
    <t:MenuItem id="item2_1" name="item2_1" action="/mytest/guess/response.jsp"/>
    <t:MenuItem id="item2_2" name="item2_2" action="http://www.msn.com"/>
    <t:Menu id="menu3" name="menu3">
    <t:MenuItem id="item3_1" name="item3_1x" action="http://www.msn.com"/>
    </t:Menu>
    </t:Menu>
    </t:Menu>
    <t:MenuItem id="item3" name="item3" action="http://www.cnn.com"/>
    </t:MenuBar>
    <!-- End Menu -->
    In the response it looks like this -
    <!-- Start Menu -->
    <t:MenuBar id="bar2" styleClass="myClass" >
    <t:MenuItem id="item3" name="item3" action="/mytest/guess/greeting.jsp"/>
    </t:MenuBar>
    <!-- End Menu -->
    and every time a menuItem is clicked on, the JS calls submit form.
    Since the menus are rendered, I assume there's nothing wrong with the rendererType and any other renderer problem. Since the decode is called only once, I assume the right form is being submitted.
    So, what can cause it to stop calling the decode ???
    Could it be that becase I go directly to the page and not through the navigation rules ( I call window.open directly from the JS), it creates a problem ??
    Please help, I've been wasting so much time on this !
    Netta.

  • Custom Validator for a Custom Component

    I am having troubling passing values from my custom component
    to my custom validator (via a model). For some reason when the
    validate() function is called for the validator the value parameter
    passed to the validator is not showing the value from my custom
    component.
    I have attached some example code to illustrate.
    Here is my model:
    <mx:Model id="myModel">
    <root>
    <mod>
    <name>{myTextInput.text}</name>
    <date>{myDateField.selectedDate.getTime()}</date>
    <length>{myComp.getLength()}</length>
    </mod>
    </root>
    </mx:Model>
    When I update the value of myTextInput or myDateField the
    model (as sent to the validator) shows the correct value. When I
    change the value of myComp the change is not reflected.
    Is there a particular event (or something) being dispatched
    in the other components to cause the model to get the new value
    that I need to include in my custom component? I am pretty stuck
    and would appreciate any help.
    Many thanks

    Does myComp extend EventDispatcher (or any class which does)?
    You need to flag the getLength() function as bindable and to
    dispatch an event:
    [Bindable('getLengthChange")]
    public function getLength() : Number
    // does whatever it does
    When you update myComp have it dispatchEvent( new
    Event("getLengthChange") ) and I think it will work.

  • Can I define a constructor for a Custom Component?

    I have a custom component which I instantiate through ActionScript.  For the sake of clean code, I would like to be able to assign the variables through the constructor like any other class:
    var myComp:CustomComponent = new CustomComponent(arg1, arg2, ...);
    However, when I try to write a constructor in the Script block for the component, it gives me a compile error telling me that I have multiple constructors:
    //In Script tag//
    public function CustomeComponent(arg1, arg2 ...):void { ... }
    Are we not able to define constructors for Custom Components?

    If this post helps, please mark it as such.
    If you create an array variable in your MXML component, and then set it with myVar="[val1, val2, val3]" in the opening tag of your component, then you basically have a constructor in MXML.
    You can use the [Bindable] metadata tag in three places:
    Before a public class definition.
    The [Bindable] metadata tag makes usable as the source of a binding expression all public properties that you defined as variables, and all public properties that are defined by using both a setter and a getter method. In this case, [Bindable] takes no parameters, as the following example shows:
    [Bindable]
    public class TextAreaFontControl extends TextArea {}
    The Flex compiler automatically generates an event named propertyChange, of type PropertyChangeEvent, for all public properties so that the properties can be used as the source of a data binding expression.
    If the property value remains the same on a write, Flex does not dispatch the event or update the property, where not the same translates to the following test:
    (oldValue !== value)
    That means if a property contains a reference to an object, and that reference is modified to reference a different but equivalent object, the binding is triggered. If the property is not modified, but the object that it points to changes internally, the binding is not triggered.
    Note: When you use the [Bindable] metadata tag before a public class definition, it only applies to public properties; it does not apply to private or protected properties, or to properties defined in any other namespace. You must insert the [Bindable] metadata tag before a nonpublic property to make it usable as the source for a data binding expression.
    Before a public, protected, or private property defined as a variable to make that specific property support binding.
    The tag can have the following forms:
    [Bindable]
    public var foo:String;
    The Flex compiler automatically generates an event named propertyChange, of type PropertyChangeEvent, for the property. If the property value remains the same on a write, Flex does not dispatch the event or update the property.
    You can also specify the event name, as the following example shows:
    [Bindable(event="fooChanged")]
    public var foo:String;
    In this case, you are responsible for generating and dispatching the event, typically as part of some other method of your class. You can specify a [Bindable] tag that includes the event specification if you want to name the event, even when you already specified the [Bindable] tag at the class level.
    Before a public, protected, or private property defined by a getter or setter method.
    You must define both a setter and a getter method to use the [Bindable] tag with the property. If you define just a setter method, you create a write-only property that you cannot use as the source of a data-binding expression. If you define just a getter method, you create a read-only property that you can use as the source of a data-binding expression without inserting the [Bindable] metadata tag. This is similar to the way that you can use a variable, defined by using the const keyword, as the source for a data binding expression.
    The tag can have the following forms:
    As far as binding, you can add the [Bindable] tag before the class declaration to make bindable all public properties defined as variables, and all public properties defined by using both a setter and a getter method.

  • Icon for a Custom Component

    Hi --
    I am building a custom component and I have tried to create
    the icon for the
    component using
    [IconFile("iconMaskInput.png")]
    but its not working. Can someone help me out?
    Rich

    Hi --
    I followed your instructions and updated the icon for the
    movie clip inside
    my FLA file that I compiled into a SWC file. However, when I
    installed the
    SWC file the icon did not update in the palette. Is this
    because I had
    already installed the component once? Or did I do something
    wrong?
    Thanks
    Rich
    "gnfontaine" <[email protected]> wrote in
    message
    news:fm4dqs$or1$[email protected]..
    > You need to add it to the component inspector first,
    then copy it into the
    > same
    > folder where you create the install package.
    >
    > 1.) Under the component definition found in the library,
    click the default
    > icon You will be present with a list, the last choice is
    custom.
    > 2.)Check the box display in components panel.
    > 3.)If you are going to distribute the component using
    mxp package, make
    > sure a
    > copy of the component is in the same folder as the mxi
    file and that you
    > add it
    > to the files node in the mxi definition.
    >
    > Hope this helps
    >

  • Dynamic visibility for a custom component

    Hi everybody,
    I have implemented dynamic visibility for my component and try to use it with the Xcelsius checkbox.
    At preview my component is visible as the checkbox is checked.
    I unchecked the checkbox then my component is no more visible,  and it is works fine.
    But when I checked the checkbox again, my compoenent doesn't appear any more...
    Any idea ?

    Hi Evan,
    I am developing a component which requires "Dynamic Visibility" property.
    Its an Icon component where I have to bind a value for Icon. (i.e 0-30 Smiley, 31-70 dash, 71-100 Frown)
    The dynamic visibility works fine only when I bind both (Value for Icon,  Dynamic Status) to the same excel cell.
    Looks like Xcelsius wants all the bindings to be done to same cell in the Excel.
    [Here|http://docs.google.com/View?id=dzf62p8_35gc73brzm] is my code for your review.
    Please help me. Your timely respose would be of great help for me.
    Thanks
    Ravi.

  • How do I automate a custom component not implementing UIComponent?

    I have tried using Adobe's instructions for automating custom components by creating a delegate class to use as a mixin, but
    1)  the super() statement in the delegate of the constructor is not recognized by the compiler,
    2) I am not able to use a DisplayObject as an argument to init(),
    3) I am not able to return the custom component as a IAutomationObject from the parent component's getAutomationChildAt method.
    Is it simply not possible to automate a custom component not implementing UIComponent?

    If you look in the library panel, there should be an entry for your custom component - probably something like CustomComponent1.mxml. Drag this out onto the artboard to create a new instance of the component.
    In the case of a custom component, you can't change much on the second instance. If you have something like a text input skin though, you can change the text it is displaying for each instance.
    We are working on making this sort of thing easier in the future, so stay tuned

  • JPanel won't display my custome component

    Hi,
    I made a custome component class that in its paint method at this stage is suppose to paint a white rectangle on screen. However the when I add this custome component to my JPanel it doesn't show up. Does anybody have a solution for this?
    My code for the custome component is,
    public spaceMediaDisplayObject(mediaObject mo){
         x = mo.getSpaceX();
         y = mo.getSpaceY();
         height = mo.getHeight();
         width = mo.getWidth();
         name = mo.getName();
         System.out.println("Constructor");
         this.repaint();
    public void paint(Graphics g){
         System.out.println("Draw");
         g.setColor(Color.white);
         g.drawRect(x, y, height, width);
    And the fragment of code I am using to try and display in on the panel is as follows,
    spaceMediaDisplayObject smdo = new spaceMediaDisplayObject(toDisplay);
         spaceBodyPanel.add(smdo);
    Please help if able.

    If it's null then you need to set the size of each component explicitly:
    JPanel panel = new JPanel(null);
    Component customComponent = new CustomComponent();
    panel.add(customComponent);
    customComponent.setBounds(0, 0, 100, 100); // For exampleA simple layout manager could be used to make the component fill the panel, for example:
    JPanel panel = new JPanel(new GridLayout(1, 1));
    panel.add(new CustomComponent());Hope this helps.

  • How do I tie a custom-component to a class?

    In flash there's this great way of seperating code from
    content: In the properties menu of a movieclip in your library, you
    can assign a class name to the movie. So something I very regularly
    do is:
    class MyMovieClip extends MovieClip{
    //etc..
    so I'd have all the code that manages my movies nicely tucked
    away in some .as files, no code in the fla. That's the way I like
    it.
    So I was wondering if you can do a similar thing in Flex. I
    most definitely don't want the code for my application in the .mxml
    file, I actually want to inherit the Application class. Similarly,
    I'd like to inherit the Canvas class, yet have the nice gui for
    dragging all the visuall elements in place. Is there a way?
    Regard, and thanks in advance,
    Karel

    If you look in the library panel, there should be an entry for your custom component - probably something like CustomComponent1.mxml. Drag this out onto the artboard to create a new instance of the component.
    In the case of a custom component, you can't change much on the second instance. If you have something like a text input skin though, you can change the text it is displaying for each instance.
    We are working on making this sort of thing easier in the future, so stay tuned

  • How do I reuse a custom component in Flash Catalyst?

    All-
    I'm sure this is easy, I simply can't figure it out.  I've created a custom component in Flash Catalyst with two states, open and closed.  I'd like to reuse this component in my app with different text assest.  How is this done?  Duplicating the component isn't available in this version...do I need to recreate the whole thing with different text?
    Cheers,
    `me

    If you look in the library panel, there should be an entry for your custom component - probably something like CustomComponent1.mxml. Drag this out onto the artboard to create a new instance of the component.
    In the case of a custom component, you can't change much on the second instance. If you have something like a text input skin though, you can change the text it is displaying for each instance.
    We are working on making this sort of thing easier in the future, so stay tuned

  • Actionscript in a Custom Component

    Can anyone tell me if you can put actionscript inside of a
    custom component? It throws errors anytime I try to do it.
    I have a horizontallist component that is being populated
    with an itemrenderer which holds an image component. The
    horizontallist takes fifteen images and loads them into the
    itemrenderers, creating a scrollable image slideshow.
    I am trying to get it to check to see if the image loaded
    successfully, and if not, either set the visibility of that image
    component to false, or remove it.
    Here is the code for the horizontallist:
    <mx:HorizontalList
    id="imageBar"
    itemRenderer="listingImage"
    height="330"
    width="925"
    paddingLeft="5"
    paddingRight="5"
    rollOverColor="#FFFFFF"
    selectionColor="#FFFFFF"
    >
    And the code for the custom component.....
    <mx:Canvas
    xmlns:mx="
    http://www.adobe.com/2006/mxml"
    height="320"
    width="400"
    verticalScrollPolicy="off"
    horizontalScrollPolicy="off"
    >
    <mx:Image
    source="
    http://www.urladdress.com/idx/rmls/images/resimages/{data.id}_{data.imageNum}.jpg"
    height="300" scaleContent="true"
    />
    </mx:Canvas>
    I'm pretty new to Flex, so any help would be great!

    just insert the script tags in the custom component and place
    your actionscript within those script tags. So in your case just
    insert the following script tags above the image control...
    <mx:Script>
    <![CDATA[
    // actionscript goes here
    ]]>
    </mx:Script>
    - Tony

  • Custom Component in CREF

    Hi everybody!
    I am trying to deploy an applet which contains a Custom Component using CREF as simulator. That means I run CREF to be waiting for incoming APDUs. By means of apdutool I run the script which contains the APDUs for the deployment of the applet. The whole CAP file is deployed properly until the custom component is tried to be deployed. Then I receive the status word 0x6424.
    That means, according to the specification:
    Exception occurred.
    * Cause: General purpose error in the installer or applet code.
    * Solution: Check your applet code for errors.
    The applet works properly without the custom component, so the problem is not in the applet code.
    The line of the script which fails is the following (where 10 is the tag chosen for the custom component): 0x80 0xB2 0x10 0x00 0x00 0x7F;
    It is the one used to prepare the Installer to receive the component whose tag is 0x10, that is what 0xB2 means.
    The response is: CLA: 80, INS: b2, P1: 10, P2: 00, Lc: 00, Le: 00, SW1: 64, SW2: 24
    The following APDUs, after that one, return 0x6421 that means the Installer is in an error state.
    So, I was wondering if someone had the same problem. Or if someone knows if CREF does not accept custom components.
    Thanks in advance, I don't reach to find where the error is. May be I am missing something...
    Best regards,
    E_L

    I would be surprised if CREF supports custom components. It would know how to use them so it would not make any sense. What is it that your custom component does?
    Cheers,
    Shane

  • How to handle children of custom component

    Hi,
    does anybody know an example of how to develop a custom UIComponent which is able to render any kind of child? For example:
    <x:mycomponent columns="3" valu="#{list-of-items} var="item">
    <h:graphicImage url="#{item.url}/>
    <h:selectBooleanCheckbox />
    </x:mycomponent>
    The result should be a table with 3 columns where each table-cell contains the result of the rendering process of its children, in this case a picture with a checkbox.
    I have tried it and managed to get the correct html-result. But I do not get the input of the checkbox if the above code snippet is a part of a html-form.
    So what I realy like to have is the sourcecode of some kind of UIComponent which does something like this.
    Kind Regards,
    Tobias

    Thanks for the swift reply Craig
    My custom component has 3 elements hence the currentTarget
    could be either the folder icon, the status icon or the text field.
    Is there some way of finding the parent of which ever of
    these sub items of the cusom component is clicked?
    Here is the code for my custom component
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Canvas xmlns:mx="
    http://www.adobe.com/2006/mxml"
    width="240" height="60" cornerRadius="15" borderStyle="none"
    backgroundColor="#ffffff" themeColor="#ff0000">
    <mx:Script>
    <![CDATA[
    [Bindable]
    public var studentName:String ="Student Name";
    ]]>
    </mx:Script>
    <mx:Text x="64" y="24" text="{studentName}" />
    <mx:SWFLoader x="10" y="10" width="32" height="24"
    source="@Embed('assets/folderIcon.swf')" />
    <mx:SWFLoader x="19" y="42" width="11" height="11"
    source="@Embed('assets/cfStatusIcon.swf')" />
    </mx:Canvas>

  • Custom Component or Other solution to this problem...

    Hello,
    In my pages I have a wizard type menu consisting of:
    [ prev   curr-title    next ]
    The code to build this menu looks like so:
    <h:panelGrid
         id="top_flow_navigation"
         columns="3"
         styleClass="wizardNavTable"
         columnClasses="wizardNavColumn_Prev,wizardNavColumn_Curr,wizardNavColumn_Next">
         <h:commandLink
              action="back"
              accesskey="n">
              <h:outputText value="#{messages['flow.user.other.main.heading']}"/>
         </h:commandLink>               
         <h:outputText value="#{messages['flow.user.personal.main.heading']}"/>
         <h:commandLink
              action="submit"
              accesskey="n">
              <h:outputText value="#{messages['flow.user.security.main.heading']}"/>
         </h:commandLink>     
         <h:outputText value="#{messages['global.button.prev']}"/>                    
         <h:outputText/>                                             
         <h:outputText value="#{messages['global.button.next']}"/>
    </h:panelGrid>This code is currently repeated at the top and bottom of each page, and also on all the pages involved in the wizard.
    The only difference in the code on each page is the messages string.
    What I would like to know is ...:
    (1) how best to solve not repeating myself at the top and bottom of each page.
    JSP include would solve this, is there a JSF way?
    (2) ...it possible to wrap this code in a jsp tag and pass in the messages binding string as a parameter...I have tried this before but sadly passing #{...} into a tag throws up errors.
    Is wrapping this all in a custom JSF component the solution?
    Thanks.
    JC.

    Create a custom component. You may define your own attributes to pass the parameters.
    For example:<custom:component messages="blah" />

  • Importing a custom component from Flash Catalyst with Assets

    I am experimenting with Flash Catalyst to see if it would work well for us to create components for Flash Builder to use. As a test I created a very simple component with a Pie Chart and a button and exported it as a fxpl file. In Flash Builder I created a Flex library project and imported the component to it. When I tried to use the component in a trivial test app it gave me an error, saying 'Could not resolve <graphics:fc_pie> to a component implementation', presumably because it had not put the component files in the right place of the library tree - by default they were put in a folder at the same level as components but with the name of the component, below which it had a components folder and an assets folder. If I move the files in these folders to the corresponding folders under src then it works fine.
    The question is, how do I get Flash Builder to do this correctly? I assume I'm missing something obvious but I am a real Flash Builder Novice and this process is about evaluating which tools to use. Sorry if I'm being a numpty. I'm using Flash builder 4.5 and Flash Catalyst CS5.5.
    Any help much appreciated.

    If you look in the library panel, there should be an entry for your custom component - probably something like CustomComponent1.mxml. Drag this out onto the artboard to create a new instance of the component.
    In the case of a custom component, you can't change much on the second instance. If you have something like a text input skin though, you can change the text it is displaying for each instance.
    We are working on making this sort of thing easier in the future, so stay tuned

Maybe you are looking for

  • HT204053 How do I add my new Mac to my iTunes account?

    how do you add a new computer to your iTunes account? I know it can only managae 4 computers. Presently I am doing well in this area. Thanks

  • Skype not doing anything.

    Just installed. It's just a blank splash screen with the rainbow and the clouds. Nothing on it. I click sign in from the icon at the bottom and nothing happens. Stays stuck like this for hours. Please help. I have an important business meeting. Was g

  • Organizational Units with Business Partner

    Hi Experts, I'm creating my organizational structure on CRM system: on transaction "PPOMA_CRM" I'm creating all the organizations I need. But I 'm facing with a problem: I'm not able to assign them a business partner. I mean: in the transaction "PPOM

  • How to find Lightroom 5 to download as per the $9.99, 12 month deal?

    Photoshop cc was listed and downloaded just fine, but Lightroom is no where to be found---that I can see.  I hate to cancel before I even get started, but I don't want half the deal!

  • Satellite M100 - DVD-Multi-Drive not recognized as CD/DVD recorder (!)

    Hello, after installing Win XP SP3 in the last windows update, the Toshiba tools as well as other CD/DVD-burning software don't recognize the DVD-ram drive as such, only as a CD-rom-drive. Thus, software like recordIt doesn't work. I have already rem