UIManager & Custom UIs

In my test application I have:
- A custom LookAndFeel installed (extends MetalLookAndFeel)
- GreenPanelUI and RedPanelUI which both extend BasicPanelUI
Their paint methods draw a small green or red square in top left of the panel.
- MyPanel which extends JPanel and uses GreenPanelUI as its default UI.
- In my application JFrame I have:
1 an instance of JPanel
2 an instance of JPanel with setBackground(Color.red);
3 an instance of MyPanel
4 an instance of JPanel with setUI(RedPanelUI) & setBackground(Color.yellow)
- There is also an editor which enables the user to change the UIDefaults for Panel.background. Everytime this is done SwingUtilities.updateComponentTreeUI( <my test app> ) is called to update the colours.
When I start my app everything is fine and works as expected
1 is grey - as expected from subclassing MetalLookAndFeel
2 is red
3 is grey with a green square
4 is yellow with a red square
Now when things go wrong is when the user chooses a new colour Panel.background. i.e.
UIManager.put("Panel.background", new ColorUIResource(Color.blue));
SwingUtilities.updateComponentTreeUI( <my test app> );
Now;
1 is blue - GOOD
2 is red - GOOD
3 is blue with a green square - GOOD
4 is yellow - BAD
Okay, I presume the SwingUtilities.updateComponentTreeUI has caused the default UI to be reinstalled for each JPanel.
This where my knowledge and understanding of the use and scope of UIManager & L&F is lacking, 'cos what I'd like to do is call the setUI method on numerous instances of JPanel to install numerous different PanelUIs (which I know does work).
However, this business of SwingUtilities.updateComponentTreeUI resetting the UI delegate is, for me in this case, annoying.
It seems as if the only to keep the UI delegate is to subclass the JPanel and set its default UI with the UIManager. Therefore if I wish to display 5 Panels each with a different PanelUI then I must also create 5 different Panel subclasses. Surely this can't be right!!!
Would appreciate any help or thoughts on this one.
Thanks

Any UI specialists out there? Please? Help??

Similar Messages

  • Connectivity for BPM external custom UIs

    Hi all,
    I'd like to use the new PO feature of BPM tasks based on custom UIs deployed on external servers as documented on the help
    Of course the application implementing the UI will be connecting to the BPM engine to fetch process data.
    My question is related to connectivity the other way around:
    does the BPM engine strictly need connectivity to the remote server where UIs are deployed?
    In my understanding it should not be necessary since the url configured in http destination is only used by the user browser.
    However I'm not sure whether it might be required for proper behavior or SSO.
    Could anyone please assist?
    Thanks, regards
    Vincenzo

    Hi Vincenzo,
    Basically it boils down to access. Your BPM Server should have permission to access the Remote Server Destination. My guess would be that this HTTP destination should already be configured in your Server's NWA 'Destinations' settings.
    The name which you define at the time of http destination setup, would be used inside the placeholders when you define the UI-URL while assigning the task.
    So the name would be something like: "{name_of_http_destination_in_nwa_setup}/Relative-url"
    Configuring the destinations would be somewhat similar to step#3 in this document.
    Please let us know if you resolve this. Would be great to know something we haven't got a chance to try yet.
    Cheers Mate.

  • CS5 Mac, Application Frame, and shelled custom UIs

    Just discovered that in CS5/5.1, when Photoshop has "Application Frame" turned on and an image is opened not in tabbed mode (ie. is floating), when we launch our custom UI is shows up BEHIND the image. Our custom UI is actually run a separate process, so we basically block PS until we return. While blocked, any other application run from the Finder (unless it is dialog-based) will show up BEHIND the image in Photoshop.
    Anyone know of a way to work around this? Can I let PS idle in an event loop of some kind? Funny how OS X doesn't have the concept of application-specific window priorities.

    Anyone? This seems to happen if anything blocks Photoshop for whatever reason. Do we need to send some events to Photoshop to tell it to clean up its global window priority while we do our thing?

  • Reset custom effect UIs?

    Hi,
    I've built an effect plugin which has 2 custom UIs in it. I want to reset these UIs to their default states when the user clicks the plugin's "Reset" hyperlink, but I can't figure out how to do so. Any ideas?
    Thanks,
    Neil

    PF_Cmd_SEQUENCE_RESETUP doesn't get called when I click Reset.
    I've got PF_OutFlag_SEQUENCE_DATA_NEEDS_FLATTENING set in order to flatten/unflatten the sequence data. The Resetup command does get called for the Open/Save/Duplicate events.
    The only command that gets called when I click Reset is PF_Cmd_USER_CHANGED_PARAM, because I specified PF_ParamFlag_SUPERVISE on 2 other params (not the 2 custom UI ones).
    The custom UIs are created with PF_ADD_NULL, which I believe has no data stream. I tried changing them to PF_ADD_COLOR but PF_Cmd_SEQUENCE_RESETUP still didn't get called when I clicked Reset.
    The reason I'm using PF_ADD_NULL is because I don't want the custom UI param to appear in the Timeline panel.
    Thanks,
    Neil

  • Magic Bullet Looks, Why not GPU?

    Why these kind of plugins are not GPU accelrated, Its very hard to work on 1980x1080 footage if u apply MBL.
    Even CS6 can't do any magic on this. I heard somwhere in FCP, MBL runs like butter.

    You may have told us, Jim.  That doesn't mean you're necessarily right now does it!
    From the Red Giant web site...
    Paul – This is from Stu Maschwitz’s blog, and may answer your questions:
    “Both Adobe Premiere Pro and Final Cut Pro bypass their own plug-in SDKs for their native 3-way color correctors. They use window configurations and graphics drawing routines that third-party developers don’t have access to. On some systems this can make UI interaction for third-party effects with Custom UIs slow. In the case of Premiere Pro, the slowness can be bad. Real bad.
    Have you noticed that Premiere’s own 3-way color corrector has never been ported to After Effects? This is one consequence of the Premiere team’s choice not to use their own plug-in SDK. Another is that third parties cannot provide a fluid custom UI experience within Premiere Pro.
    After Effects, on the other hand, “eats its own dog food,” and has no effects that don’t use the public SDK. This means that third parties can create excellent user experiences within After Effects. The benefits to us users are obvious — just look at all the amazing plug-ins available for After Effects.
    Premiere Pro and After Effects actually share the same plug-in SDK. This is amazingly cool, because it means that, for example, you can start a project in Premiere, use Colorista II all you want, and then move the project to After Effects, keeping all your settings. But despite this shared architecture, plug-ins like Colorista II sing in After Effects and bog down in Premiere.
    Red Giant has is committed to working with Adobe to resolve this situation. We love Premiere Pro and feel that it and Colorista were born for each other. The playback performance is amazing. We’ve done the best we can with what we have. If you try Colorista II in Premiere and find the performance lacking, please consider contacting Adobe and asking them to improve the performance of Custom UI plug-ins written to their own SDK.”

  • How can a Swing JWindow be resized without flickering?

    Hi,
    I'm having trouble trying to get a custom UI I have made based on JWindow to resize in an acceptable way due to the amount of flicker.
    The problem is described here:
    http://stackoverflow.com/questions/4324221/how-can-a-swing-jwindow-be-resized-without-flickering
    I have tried various attempts at (manual) double buffering but it seems that nothing can help with the fact that the top window's ComponentPeer is resizing the window and drawing it with a 'stale' view of the layout and then doing the new layout afterwards. This happens for me in Windows XP and Ubuntu Linux under Sun/Oracle Java 1.6.0_u22 (latest), and apparently in Windows 7 too.
    I am unsure if this is a bug, defect or is this way by design. I also notice that Netbeans suffers from the same issue on resizing but Eclipse does not. Does this mean that Swing is currently incapable of laying out/painting a top level Component to a back buffer before drawing to the screen? Does this affect/annoy anyone else?
    Or if not, any ideas how a smooth redraw can be achieved?
    I understand that this issue does not bother everyone, but for custom UIs like the one I am trying to achieve the result is not really acceptable.
    Any help much appreciated!

    Thanks that's an interesting approach, I think I may use...
    AWTUtilities.setWindowShape(jWindow, newshape)...on a JWindow set to be the same size as the entire desktop as I need the UI to remain in place whilst allowing mouse and key events to reach other applications.
    Does any one think it would be worth submtting a bug report or feature request for the desired behaviour?
    That is: getting top level (heavyweight) containers to layout and repaint into a back buffer, and provide this buffer to the underlying window manager during the resize so that 'stale' window layouts are not drawn to the screen during resizing. This is the way SWT appears to function and so should be possible in theory.

  • AE SDK wrapper

    Hi
    I've just been working on a project writing AE plugins - mostly fairly basic things like drawing and animating geometric shapes. This has been my first foray into After Effects plugins. However in doing so I must confess to finding the API painful and the documentation impenetrable. It has taken me the best part of a year working on-and-off on this project to feel comfortable writing basic plugins - and I never even got as far as smart plugins.
    Anyway, along the way I've begun to write a series of C++ wrappers around the API to manage resources, things like an multi-d array class to correctly handle AE memory management, some transformation code using the after effect matrix structure and the beginnings of a World class for managing AE_Worlds and doing drawing etc. I was wondering if there was any demand for this kind of thing in the community and if it was worth me developing further? The kind of thing I'm imagining is a more object oriented and easier to use interface to the SDK, with better resource management - to save the memory leaks. I know the code I've written already has massively speeded up my plugin development and reduced bugs. Maybe it would be some help to others.
    In the end though, I'm self employed so it boils down to would anyone be interested enough in a "nice" API interface to buy it and make it worth my time developing. I wondered if anyone here had any thoughts or even might be interested in a finshed product?
    Phil

    well, here are my 2 cents about this issue.
    any modernisation of the AE API would be a welcome change. i of course am
    using my own libs made over time.
    will there be a demand for a payed AE super lib? i'll try to break it down,
    to the best of my knowledge.
    from what i gathered from my years at the forum, there are 3 demographics
    here.
    i'd say the breakdown is like so (based on intuition, not research):
    1. 30% are complete noobs, with very little or no programming experience,
    usually AE artists with an idea they'd like to fiddle with.
    noobs are less likely to buy a library, as they have little prospect of
    what their product will become. it's more of an intellectual challenge for
    them, and actually using a crude c code is easier for a noob than learning
    c++ concepts. however, noobs can evolve into semi-pros.
    common problems noobs hit:
    a. adding new params (to be set at 3 different places).
    b. allocation and deallocation of objects.
    c. image processing, not via a suite.
    d. a dire need for better sample projects.
    2. 50% are semi pro programmers with AE experience, and a better grip of
    what their idea entails, and what it's worth.
    semi-pros may buy a library, if they had failed at solving a certain
    problem by themselves and the price is right. i'd imagine most semi-pros
    develop on their spare time and make a living elsewhere, so they'd rather
    spend more time than spend money. (again, until they hit a wall or come to
    a realization that it's better to buy a lib)
    common problems semi-pros hit:
    a. combination of AEGP style project operations in an EFFECT plug-in.
    b. custom UIs.
    c. an even bigger dire need for better sample projects than that of a noob.
    3. 20% are professional programmers, with little or no AE experience,
    executing a commissioned work by a 3rd party.
    commissioned pros on the other hand, they have a budget and a schedule.
    they're used to using off the self libraries and consider it a shortcut.
    surprisingly enough, even seasoned pros run into walls with AE's API. so
    they're rather a sure sell. (given they know of your library, and it offers
    a solution to the problem they've hit)
    common problems pros hit:
    a. wasting time learning the API nuances and subtleties. (and there are
    many)
    b. realizing what the API limitations are.
    c. overcoming API limitations. (doing stuff against AE's will)
    all 3 demographics would LOVE to have more sample projects, and better
    sample project.
    my guess is, that if your library is of good enough quality, has
    interesting enough sample projects, and will be brought to the attention of
    the developer, you'll see some sells.
    there's a world surge of AE development. for the last 2 years i saw the
    demand increase x2 each year. i don't know when that surge will peak, but
    it's there.
    i also don't know how to estimate the market size. in this forum there are
    about 20 active users, so i'm guessing there are a mere few hundreds AE SDK
    developers out there at best. is the library development worth while?
    depends entirely on your costs of development, and whether such tools
    evolve from your actual project's work or are you developing the library as
    a project on it's own merit.
    these have been my 2 cents.
    please take everything here as my personal opinion and not as a fact.
    having said that, i hope it helped.

  • Creating a gui with j2me

    Hi, I'm making a midlet, and I want to create a gui. i think the best way for making this is using canvas, but I can't find any tutorial/example. The gui would be something like this:
    http://bladecoder.net/hof/images/sf1.png
    ah, and I cannot use j2mepolish.
    Thanks for your help.

    Please start with the link mentioned above. After discovering the APIs you need you can find numerous examples of custom UIs.
    A couple of years ago there was a great example of creating a a custom UI framework on the web. I cant seem to find it now. The closest thing I could find now is http://www2.sys-con.com/itsg/virtualcd/Java/archives/0606/cordrey/index.html
    Visit the Nokia and SE developer site. SE, especially, always has good examples.
    I use the low level API for all my J2ME work. As an aside, you can look at some of my "weekend" projects. Here are some screenshots.
    http://mobox.cliqcafe.com/files/1439/rim-5.jpg
    http://mobox.cliqcafe.com/files/1831/Screenshot0036.jpg
    http://hostj2me.cliqcafe.com/files/2382/Screenshot0619.jpg
    Grab the source if you like, but learn the basics first. I would not want you to inadvertently pick up any of my "bad habits." If you have time to waste, and dont mind lax production:), you can watch video demo an custom ui here:
    http://hostj2me.cliqcafe.com/files/1877/yipi.wmv

  • Configuring parameter fields in Search Bar pattern UI configuration

    Hello all,
    Im configuring a search bar UI pattern for an entity service and have some doubts. The parameter fields description seems to be the entity service field description.
    - Is there a way to internationalize this field descriptions ?
    - The search bar always generate a button called "Go". Is it possible to change the button text ?
    Thanks in advance,
    Helder Ribeiro

    Thanks Abdul, but where in CAF Runtime configurator?
    Regarding the recommendation of custom WDP or VC app: Under what circumstance would one use the UI patterns.  Again our desire is to find the limit of configuring UI patterns vs. custom UIs.

  • How to detect a mouse release event?

    AE SDK provides events for mouse click and mouse drag over effect plugin custom UIs, however there does not seem to be events for mouse release events.
    Are we supposed to keep ourselves an internal track of the mouse status? In that case, do we need to use OS-specific functions? Or is there a more clever way to do it?

    @shachar
    Yes, I set send_drag during the DoClick event callback, like they do in the SDK samples.
    Anyway, for the time being I found that using OS-specific functions (for example GetAsyncKeyState for Windows) does the job.

  • Darren's Weekly Nugget 04/13/2009

    In LabVIEW 8.6, I included a set of VIs in vi.lib\UserTags for assigning tags to objects in your VIs (or to VIs themselves).  Tags are basically just name/value pairs that you can assign to any VI or any object in a VI.  Tag names/values are persisted when you save the VI after assigning a tag.  There are several possible use cases for tags, here are just a few:
    Marking certain VIs with tags so they can be easily identified by plug-in frameworks.  For example I could assign a certain tag to VI Analyzer test VIs so that the VI Analyzer would not load any test VI that did not have this custom tag set.
    Including configuration information for controls/indicators on custom UIs to avoid having to synchronize with a separate database.  When I worked on the Simulation Interface Toolkit many years ago, I stored model parameter mapping information for front panel controls/indicators as tags in the controls/indicators themselves.  That way, if you renamed or deleted a front panel item, I wouldn't have to go searching in a separate database to figure out which object needed renaming or deletion...the parameter mapping information simply stuck around with the renamed control (or disappeared along with the deleted control).
    Assigning unique identifiers to front panel decorations.  This use case was discussed in this thread.
    Prior to LabVIEW 8.6, tags were only available with private VI Server methods...in fact, the VIs in vi.lib\UserTags wrap these private methods, with a few caveats attached:
     You cannot store refnum or LabVIEW Class data in a tag.
     Internally, I append "user." to the beginning of any tag name set by these VIs.  That way, we can be sure that user tags do not generate name conflicts with any existing internal NI tags that may already be set on VIs or objects.
    What other use cases are out there for VI/object tags?
    Darren Nattinger, CLA
    LabVIEW Artisan and Nugget Penman

    Darren wrote:
    In LabVIEW 8.6, I included a set of VIs in vi.lib\UserTags for assigning tags to objects in your VIs (or to VIs themselves). 
    Let's see if I understood correctly.  The tags are assigned to objects within the VI and not to the VI itself.  Each object within the VI can have one or more tags assigned to it.
    How would someone access these from outside LabVIEW?
    R

  • Custom UIManager

    Hello,
    I have a class which change the UIManager (UIManager.put(...)).
    When the application starts, I have any problem.
    But during the use of the application, the user can change the values in the UIManager.
    When the values are inserted into the UIManager, I execute 'updateUI()', but the update is no visible, the objects keeps theirs gfx representation.
    Help me please =)
    Pierre Carpentier

    Here is a section from the Java Swing tutorial that explains how to solve this problem:
    http://java.sun.com/docs/books/tutorial/uiswing/misc/plaf.html#dynamic
    The Swing tutorial is a great place to start for all Swing problems. It can be download for free from:
    http://java.sun.com/docs/books/tutorial/

  • Custom button UI Problem

    Hi all,
    I have written CustomButtonUI for JButton.
    But, it results into error.please suggest me.
    Here is the code:
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Rectangle;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.accessibility.Accessible;
    import javax.swing.AbstractButton;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.UIManager;
    import javax.swing.plaf.ComponentUI;
    import javax.swing.plaf.basic.BasicButtonListener;
    import javax.swing.plaf.metal.MetalButtonUI;
    * CustomButtonUI.java
    * Created on March 4, 2010, 5:13 PM
    * @author  mourya
    public class CustomButtonUI extends javax.swing.JDialog {
        /** Creates new form CustomButtonUI */
        public CustomButtonUI(java.awt.Frame parent, boolean modal) {
            super(parent, modal);
            String DEFAULTCLASSID="Mybutton";
            UIManager.put(DEFAULTCLASSID, "Mybutton");
            UIManager.put("ButtonUI",DEFAULTCLASSID);
            initComponents();
            JButton jbutton = new JButton("Custom");
            jbutton.setBounds(10,10,100,20);
            add(jbutton);
            this.addWindowListener(new WindowAdapter()
                public void windowClosing(WindowEvent event)
                    System.exit(0);
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                         
        private void initComponents() {
            setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
            org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(0, 400, Short.MAX_VALUE)
            layout.setVerticalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(0, 300, Short.MAX_VALUE)
            pack();
        }// </editor-fold>                       
         * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new CustomButtonUI(new javax.swing.JFrame(), true).setVisible(true);
        // Variables declaration - do not modify                    
        // End of variables declaration                  
    class Mybutton extends MetalButtonUI
         private final static Mybutton
          mMybutton = new Mybutton();
        public static ComponentUI createUI(JComponent c)
          return mMybutton;
        protected void clearTextShiftOffset()
            super.clearTextShiftOffset();
        protected void finalize() throws Throwable
            super.finalize();
        protected BasicButtonListener createButtonListener(AbstractButton b)
            return super.createButtonListener(b);
        protected Color getDisabledTextColor()
            return super.getDisabledTextColor();
        protected Color getFocusColor()
            return super.getFocusColor();
        protected String getPropertyPrefix()
            return super.getPropertyPrefix();
        protected Color getSelectColor()
            return super.getSelectColor();
        protected int getTextShiftOffset() {
            return super.getTextShiftOffset();
        protected void installKeyboardActions(AbstractButton b)
            super.installKeyboardActions(b);
        protected void installListeners(AbstractButton b) {
            super.installListeners(b);
        protected Object clone() throws CloneNotSupportedException {
            return super.clone();
        protected void paintButtonPressed(Graphics g, AbstractButton b)
            super.paintButtonPressed(g,b);
        protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect) {
            super.paintFocus(g,b,viewRect,textRect,iconRect);
        protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect) {
            super.paintIcon(g,c,iconRect);
        protected void paintText(Graphics g, AbstractButton b, Rectangle textRect, String text)
            g.setColor(Color.GRAY);
            super.paintText(g,b,textRect,text);
        protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) {
            g.setColor(Color.GRAY);
            super.paintText(g,c,textRect,text);
        protected void setTextShiftOffset() {
            super.setTextShiftOffset();
        protected void uninstallKeyboardActions(AbstractButton b) {
            super.uninstallKeyboardActions(b);
        protected void uninstallListeners(AbstractButton b) {
            super.uninstallListeners(b);
        public boolean contains(JComponent c, int x, int y)
            return super.contains(c,x,y);
        public boolean equals(Object obj)
            return super.equals(obj);
        public Accessible getAccessibleChild(JComponent c, int i) {
            return super.getAccessibleChild(c,i);
        public int getAccessibleChildrenCount(JComponent c) {
            return super.getAccessibleChildrenCount(c);
        public int getDefaultTextIconGap(AbstractButton b) {
            return super.getDefaultTextIconGap(b);
        public Dimension getMaximumSize(JComponent c) {
            return super.getMaximumSize(c);
        public Dimension getMinimumSize(JComponent c) {
            return super.getMinimumSize(c);
        public Dimension getPreferredSize(JComponent c) {
            return super.getPreferredSize(c);
        public void installDefaults(AbstractButton b) {
            super.installDefaults(b);
        public void installUI(JComponent c) {
            super.installUI(c);
        public int hashCode() {
            return super.hashCode();
        public void paint(Graphics g, JComponent c) {
            super.paint(g,c);
        public String toString() {
            return super.toString();
        public void uninstallDefaults(AbstractButton b)
            super.uninstallDefaults(b);
        public void uninstallUI(JComponent c)
            super.uninstallUI(c);
        public void update(Graphics g, JComponent c)
            super.update(g,c);
    }Thank You

    Hi DarrylBurke,
    Sure i will.
    But i have posted that code after trying all the possibilities.
    I thought that getUI() failed exception may have the resulkt for not implementing any method or any registration problem with UIManager.
    So, that is my test code not exactly i have posted that in hurry.
    Here is the code :
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Rectangle;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.accessibility.Accessible;
    import javax.swing.AbstractButton;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.UIManager;
    import javax.swing.plaf.ComponentUI;
    import javax.swing.plaf.basic.BasicButtonListener;
    import javax.swing.plaf.metal.MetalButtonUI;
    * CustomButtonUI.java
    * Created on March 4, 2010, 5:13 PM
    * @author  mourya
    public class CustomButtonUI extends javax.swing.JDialog {
        /** Creates new form CustomButtonUI */
        public CustomButtonUI(java.awt.Frame parent, boolean modal) {
           super(parent, modal);
            String DEFAULTCLASSID="Mybutton";
            UIManager.put(DEFAULTCLASSID, "Mybutton");
            UIManager.put("ButtonUI",DEFAULTCLASSID);
            initComponents();
            JButton jbutton = new JButton("Custom");
            jbutton.setBounds(10,10,100,20);
            add(jbutton);
            this.addWindowListener(new WindowAdapter()
                public void windowClosing(WindowEvent event)
                    System.exit(0);
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                         
        private void initComponents() {
            setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
            org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(0, 400, Short.MAX_VALUE)
            layout.setVerticalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(0, 300, Short.MAX_VALUE)
            pack();
        }// </editor-fold>                       
         * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new CustomButtonUI(new javax.swing.JFrame(), true).setVisible(true);
        // Variables declaration - do not modify                    
        // End of variables declaration                  
    class Mybutton extends MetalButtonUI
         private final static Mybutton
          mMybutton = new Mybutton();
        public static ComponentUI createUI(JComponent c)
          return mMybutton;
        protected void paintText(Graphics g, AbstractButton b, Rectangle textRect, String text)
            g.setColor(Color.RED);
            super.paintText(g,b,textRect,text);
    }Can you please suggest me the possible solution for this problem.
    Thank You DarrylBurke

  • Custom component not working properly

    Hi all - I am trying to create a custom component. I have followed the suggested MVC architecture, and created the following classes:
    1. SuperLineModel (the MODEL)
    2. SuperLine (the actual component,e.g. the CONTROLLER)
    3. BasicSuperLineUI (the UI Delegate class, e.g. the VIEW)
    4. SuperLineUI (an abstract type class for my UI Delegate)
    I also have a fifth class that draws a frame and panel, and then adds the custom component to the panel. In the main method of this class, I
    register the UI delegate like this:
    UIManager.put(BasicSuperLineUI.UI_CLASS_ID, "com.volant.mapit.view.BasicSuperLineUI");Everything compiles without any problems, but the custom component is never painted for some reason. In fact, I added a print line to the UI delegates paint method just to see if it was ever called, and it wasn't. I know I'm missing something here, and it's probably something small. I'm hoping some of you Swing gurus can take a look at my code below and point out the problem for me.
    I really appreciate any help you can give me. Thanks.
    The classes are listed below:
    // SuperLineModel
    import javax.swing.*;
    import javax.swing.event.*;
    public class SuperLineModel
      private double sourceXCoord = 0;
      private double sourceYCoord = 0;
      private double targetXCoord = 0;
      private double targetYCoord = 0;
      private EventListenerList listenerList = new EventListenerList();
      public SuperLineModel()
      public SuperLineModel(double sourceXCoord, double sourceYCoord,
                           double targetXCoord, double targetYCoord)
        this.sourceXCoord = sourceXCoord;
        this.sourceYCoord = sourceYCoord;
        this.targetXCoord = targetXCoord;
        this.targetYCoord = targetYCoord;
      public void setSourceXCoord(double x)
        this.sourceXCoord = x;
        return;
      public void setSourceYCoord(double y)
        this.sourceYCoord = y;
        return;
      public void setTargetXCoord(double x)
        this.targetXCoord = x;
        return;
      public void setTargetYCoord(double y)
        this.targetYCoord = y;
        return;
      public double getSourceXCoord()
        return this.sourceXCoord;
      public double getSourceYCoord()
        return this.sourceYCoord;
      public double getTargetXCoord()
        return this.targetXCoord;
      public double getTargetYCoord()
        return this.targetYCoord;
      public void addChangeListener(ChangeListener cl)
        listenerList.add(ChangeListener.class, cl);
      public void removeChangeListener(ChangeListener cl)
        listenerList.remove(ChangeListener.class, cl);
    // SuperLine
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import com.volant.mapit.view.*;
    import com.volant.mapit.model.*;
    public class SuperLine extends JComponent implements ChangeListener
      private SuperLineModel model;
      public SuperLine()
        init(new SuperLineModel());
      public SuperLine(SuperLineModel model)
        init(model);
      public void init(SuperLineModel model)
        setModel(model);
        setMinimumSize(new Dimension(50, 50));
        setPreferredSize(new Dimension(50,50));
        updateUI();
      public void setUI(BasicSuperLineUI ui)
        super.setUI(ui);
      public BasicSuperLineUI getUI()
        return (BasicSuperLineUI)ui;
      public void updateUI()
        setUI((BasicSuperLineUI)UIManager.getUI(this));
        invalidate();
      public String getUIClassID()
        return SuperLineUI.UI_CLASS_ID;
      public SuperLineModel getModel()
        return model;
      public void setModel(SuperLineModel model)
        SuperLineModel oldModel = model;
        if(oldModel != null)
          oldModel.removeChangeListener(this);
        if(model == null)
          model = new SuperLineModel();
        else
          model.addChangeListener(this);
        firePropertyChange("model", oldModel, model);
      public void stateChanged(ChangeEvent evt)
        repaint();
    // BasicSuperLineUI
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.plaf.*;
    import com.volant.mapit.control.*;
    public class BasicSuperLineUI extends SuperLineUI
      public static ComponentUI createUI(JComponent c)
        return new BasicSuperLineUI();
      public void installUI(JComponent c)
        SuperLine sl = (SuperLine)c;
      public void uninstallUI(JComponent c)
        SuperLine sl = (SuperLine)c;
      // This method is never called and I don't know why!!!
      public void paint(Graphics g, JComponent c)
        super.paint(g, c);
        System.out.println("test2");
        g.fillRect(0, 0, 200, 400);
    // SuperLineUI
    import javax.swing.plaf.*;
    import com.volant.mapit.control.*;
    public abstract class SuperLineUI extends ComponentUI
      public static final String UI_CLASS_ID = "SuperLineUI";

    A quick glance at the code and it looks ok with the exception of the following which I don't understand what you're trying to do:
      public void installUI(JComponent c)  {
        SuperLine sl = (SuperLine)c;
      public void uninstallUI(JComponent c)  {
        SuperLine sl = (SuperLine)c;
      }Here are my comments:
    1) I expect Superline sl to be a global variable for use elsewhere in your program.
    2) I have no idea what your uninstallUI does.
    This is what I would do:
      SuperLine sl;
      public void installUI(JComponent c)  {
        sl = (SuperLine)c;
      public void uninstallUI(JComponent c)  {
      }Finally, I am assuming that the changelistener will trigger a repaint which in turn will call your paint method, right?
    ;o)
    V.V.

  • Problem with focus border and ListCellRenderer in custom listbox

    I have a bug in some code that I adapted from another posting on this board -- basically what I've done is I have a class that implements a custom "key/value" mapping listbox in which each list item/cell is actually a JPanel consisting of 3 JLabels: the first label is the "key", the second is a fixed "==>" mapping string, and the 3rd is the value to which "key" is mapped.
    The code works fine as long as the list cell doesn't have the focus. When it does, it draws a border rectangle to indicate focus, but if the listbox needs to scroll horizontally to display all the text, part of the text gets cut off (i.e. "sometex..." where "sometext" should be displayed).
    The ListCellRenderer creates a Gridlayout to lay out the 3 labels in the cell's JPanel.
    What can I do to remedy this situation? I'm not sure what I'd need to do in terms of setting the size of the panel so that all the text gets displayed OK within the listbox. Or if there's something else I can do to fix this. The code and a main() to run the code are provided below. To reproduce the problem, click the Add Left and Add Right buttons to add a "mapping" -- when it doesn't have focus, everything displays fine, but when you give it focus, note the text on the right label gets cut off.
    //======================================================================
    // Begin Source Listing
    //======================================================================
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.Collection;
    import java.util.Iterator;
    import java.util.Vector;
    import java.util.Enumeration;
    public class TwoColumnListbox extends JPanel
    private JList m_list;
    private JScrollPane m_Pane;
    public TwoColumnListbox(Collection c)
         DataMapListModel model = new DataMapListModel();
         if (c != null)
         Iterator it = c.iterator();
         while (it.hasNext())
         model.addElement(it.next());
         m_list = new JList(model);
         ListBoxRenderer renderer= new ListBoxRenderer();
              m_list.setCellRenderer(renderer);
              setLayout(new BorderLayout());
              m_list.setVisibleRowCount(4);
              m_Pane = new JScrollPane(m_list);
              add(m_Pane, BorderLayout.NORTH);
    public JList getList()
    return m_list;
    public JScrollPane getScrollPane()
    return m_Pane;
    public static void main(String s[])
              JFrame frame = new JFrame("TwoColumnListbox");
              frame.addWindowListener(new WindowAdapter() {
              public void windowClosing(WindowEvent e) {System.exit(0);}
    final DataMappings dm = new DataMappings();
    final TwoColumnListbox lb = new TwoColumnListbox(dm.getMappings());
              final DataMap map = new DataMap();
              JButton leftAddBtn = new JButton("Add Left");
              leftAddBtn.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e)
              map.setSource("JButton1");
              DefaultListModel model = new DefaultListModel();
              model.addElement(map);
              lb.getList().setModel(model);
              JButton leftRemoveBtn = new JButton("Remove Left");
              leftRemoveBtn.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e)
              map.setSource("");
              DefaultListModel model = new DefaultListModel();
              model.addElement(map);
              lb.getList().setModel(model);
              JButton rightAddBtn = new JButton("Add Right");
    rightAddBtn.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e)
              map.setDestination("/getQuote/symbol[]");
              DefaultListModel model = new DefaultListModel();
              model.addElement(map);
              lb.getList().setModel(model);
              JButton rightRemoveBtn = new JButton("Remove Right");
    rightRemoveBtn.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e)
              map.setDestination("");
              DefaultListModel model = new DefaultListModel();
              model.addElement(map);
              lb.getList().setModel(model);
              JPanel leftPanel = new JPanel(new BorderLayout());
              leftPanel.add(leftAddBtn, BorderLayout.NORTH);
              leftPanel.add(leftRemoveBtn, BorderLayout.SOUTH);
    JPanel rightPanel = new JPanel(new BorderLayout());
              rightPanel.add(rightAddBtn, BorderLayout.NORTH);
              rightPanel.add(rightRemoveBtn, BorderLayout.SOUTH);
    frame.getContentPane().add(leftPanel, BorderLayout.WEST);
              frame.getContentPane().add(lb,BorderLayout.CENTER);
    frame.getContentPane().add(rightPanel, BorderLayout.EAST);
              frame.pack();
              frame.setVisible(true);
         class ListBoxRenderer extends JPanel implements ListCellRenderer
              private JLabel left;
              private JLabel arrow;
              private JLabel right;
              private Color clrForeground = UIManager.getColor("List.foreground");
    private Color clrBackground = UIManager.getColor("List.background");
    private Color clrSelectionForeground = UIManager.getColor("List.selectionForeground");
    private Color clrSelectionBackground = UIManager.getColor("List.selection.Background");
              public ListBoxRenderer()
                   setLayout(new GridLayout(1, 2, 10, 0));
                   //setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
                   left = new JLabel("");
                   left.setForeground(clrForeground);               
                   arrow = new JLabel("");
                   arrow.setHorizontalAlignment(SwingConstants.CENTER);
                   arrow.setForeground(clrForeground);
                   right = new JLabel("");
                   right.setHorizontalAlignment(SwingConstants.RIGHT);
                   right.setForeground(clrForeground);
                   add(left);
                   add(arrow);
                   add(right);
              public Component getListCellRendererComponent(JList list, Object value,
                        int index, boolean isSelected, boolean cellHasFocus)
                   if (isSelected)
                        setBackground(list.getSelectionBackground());
                        setForeground(list.getSelectionForeground());
                        left.setForeground(clrSelectionForeground);
                        arrow.setForeground(clrSelectionForeground);
                        right.setForeground(clrSelectionForeground);
                   else
                        setBackground(list.getBackground());
                        setForeground(list.getForeground());
                   left.setForeground(clrForeground);
                        arrow.setForeground(clrForeground);
                        right.setForeground(clrForeground);               
                   // draw focus rectangle if control has focus. Problem with focus
    // and cut off text!!
                   if (cellHasFocus)
                   // FIXME: for Windows LAF I'm not getting the correct thing here for some reason.
                   // Looks OK on Metal though.
                   setBorder(BorderFactory.createLineBorder(UIManager.getColor("focusCellHighlightBorder")));
                   else
                   setBorder(BorderFactory.createEmptyBorder());               
    DataMap map = (DataMap) value;
                   String displaySource = map.getSource();
                   String displayDest = map.getDestination();
                   left.setText(displaySource);
                   arrow.setText("=>to<=");
                   right.setText(displayDest);
                   return this;
    /** Interface for macro editor UI
    * @version 1.0
    class DataMappings
    private Collection mappings;
    public DataMappings()
    setMappings(new Vector(0));
    public DataMappings(Collection maps)
    setMappings(maps);
    /** gets mapping value of a specified source object
    * @param src -- the "key" or source object, what is mapped.
    * @return what the source object is mapped to
    * @version 1.0
    public Object getValue(String src)
    if (src != null)
    Iterator it = mappings.iterator();
    while (it.hasNext());
    DataMap thisMap = (DataMap) it.next();
    if (thisMap.getSource().equals(src))
    return thisMap.getDestination();
    return null;
    /** sets mapping value of a specified source object
    * @param src -- the "key" or source object, what is mapped.
    * @param what the source object is to be mapped to
    * @version 1.0
    public void setValue(String src, String dest)
    if (src != null)
    // see if the value is in there first.
    Iterator it = mappings.iterator();
    while (it.hasNext())
    DataMap thisMap = (DataMap) it.next();
    if (thisMap.getSource().equals(src))
    thisMap.setDestination(dest);
    return;
    // not in the collection, add it
    mappings.add(new DataMap(src, dest));
    /** gets collection of mappings
    * @return a collection of all mappings in this object.
    * @version 1.0
    public Collection getMappings()
    return mappings;
    /** sets collection of mappings
    * @param maps a collection of src to destination mappings.
    * @version 1.0
    public void setMappings(Collection maps)
    mappings = maps;
    /** adds a DataMap
    * @param map a DataMap to add to the mappings
    * @version 1.0
    public void add(DataMap map)
    if (map != null)
    mappings.add(map);
    class DataMap
    public DataMap() {}
    public DataMap(String source, String destination)
    m_source = source;
    m_destination = destination;
    public String getSource()
    return m_source;
    public void setSource(String s)
    m_source = s;
    public String getDestination()
    return m_destination;
    public void setDestination(String s)
    m_destination = s;
    protected String m_source = null;
    protected String m_destination = null;
    /** list model for datamaps that provides ways
    * to determine whether a source is already mapped or
    * a destination is already mapped.
    class DataMapListModel extends DefaultListModel
    public DataMapListModel()
    super();          
    /** determines whether a source is already mapped
    * @param src -- the source property of a datamapping
    * @return true if the source is in the list, false if not
    public boolean containsSource(Object src)
    Enumeration enum = elements();
    while (enum.hasMoreElements())
    DataMap dm = (DataMap) enum.nextElement();
    if (dm.getSource().equals(src))
    return true;
    return false;
    /** determines whether a destination is already mapped
    * @param dest -- the destination property of a datamapping
    * @return true if the destination is in the list, false if not
    public boolean containsDest(Object dest)
    Enumeration enum = elements();
    while (enum.hasMoreElements())
    DataMap dm = (DataMap) enum.nextElement();
    if (dm.getDestination().equals(dest))
    return true;
    return false;
    public DataMappings getDataMaps()
    DataMappings maps = new DataMappings();
    // add all the datamaps in the model
    Enumeration enum = elements();
    while (enum.hasMoreElements())
    DataMap dm = (DataMap) enum.nextElement();
    maps.add(dm);
    return maps;
    //======================================================================
    // End of Source Listing
    //======================================================================

    I did not read the program, but the chopping looks like a layout problem.
    I think it's heavy to use a panel + 3 components in a gridlayout for each cell. look at this sample where i draw the Cell myself,
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.util.*;
    public class Jlist3 extends JFrame 
         Vector      v  = new Vector();
         JList       jc = new JList(v);
         JScrollPane js = new JScrollPane(jc);
    public Jlist3()
         addWindowListener(new WindowAdapter()
        {     public void windowClosing(WindowEvent ev)
              {     dispose();
                   System.exit(0);}});
         for (int j=0; j < 70; j++)     v.add(""+j*1000+"a  d"+j);
           setBounds(1,1,400,310);
         getContentPane().add(js);
         js.setPreferredSize(new Dimension(230,259));
         jc.setSelectedIndex(1);
         jc.setCellRenderer(new MyCellRenderer());
         getContentPane().setLayout(new FlowLayout());
         setVisible(true);
    public class MyCellRenderer extends JLabel implements ListCellRenderer
         String  txt;
         int     idx;
         boolean sel;
    public Component getListCellRendererComponent(JList list,
                             Object  value,           // value to display
                             int     index,           // cell index
                             boolean isSelected,      // is the cell selected
                             boolean cellHasFocus)    // the list and the cell have the focus
         idx = index;
         txt = value.toString();
         sel = isSelected;
         setText(txt);
         return(this);
    public void paintComponent(Graphics g)
         if (idx%2 == 1) g.setColor(Color.white);
              else        g.setColor(Color.lightGray);
         if (sel)        g.setColor(Color.blue);
         g.fillRect(0,0,getWidth(),getHeight());
         StringTokenizer st = new StringTokenizer(txt.trim()," ");
         g.setColor(Color.black);
         if (st.hasMoreTokens())     g.drawString(st.nextToken(),1,14);
         g.setColor(Color.red);
         g.drawString("===>",70,14);
         g.setColor(Color.black);
         if (st.hasMoreTokens())     g.drawString(st.nextToken(),110,14);
    public static void main (String[] args) 
         new Jlist3();
    Noah
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.util.*;
    public class Jlist3 extends JFrame
         Vector v = new Vector();
         JList jc = new JList(v);
         JScrollPane js = new JScrollPane(jc);
    public Jlist3()
         addWindowListener(new WindowAdapter()
    {     public void windowClosing(WindowEvent ev)
              {     dispose();
                   System.exit(0);}});
         for (int j=0; j < 70; j++)     v.add(""+j*1000+"a d"+j);
         setBounds(1,1,400,310);
         getContentPane().add(js);
         js.setPreferredSize(new Dimension(230,259));
         jc.setSelectedIndex(1);
         jc.setCellRenderer(new MyCellRenderer());
         getContentPane().setLayout(new FlowLayout());
         setVisible(true);
    public class MyCellRenderer extends JLabel implements ListCellRenderer
         String txt;
         int idx;
         boolean sel;
    public Component getListCellRendererComponent(JList list,
                             Object value, // value to display
                             int index, // cell index
                             boolean isSelected, // is the cell selected
                             boolean cellHasFocus) // the list and the cell have the focus
         idx = index;
         txt = value.toString();
         sel = isSelected;
         setText(txt);
         return(this);
    public void paintComponent(Graphics g)
         if (idx%2 == 1) g.setColor(Color.white);
              else g.setColor(Color.lightGray);
         if (sel) g.setColor(Color.blue);
         g.fillRect(0,0,getWidth(),getHeight());
         StringTokenizer st = new StringTokenizer(txt.trim()," ");
         g.setColor(Color.black);
         if (st.hasMoreTokens())     g.drawString(st.nextToken(),1,14);
         g.setColor(Color.red);
         g.drawString("===>",70,14);
         g.setColor(Color.black);
         if (st.hasMoreTokens())     g.drawString(st.nextToken(),110,14);
    public static void main (String[] args)
         new Jlist3();
    }

Maybe you are looking for