java - Extending existing Swing look and feels with custom JComponents -


I am writing a custom JComponent which should look different for different forms and It seems that I intend to have at least the different ComponentUi classes for WindowsLookAndFeel , MetalLookAndFeel and MotifLookAndFeel .

Now, while this work seems quite easy, I do not know how to easily expand and realize an existing form with my custom ComponentUi classes.

How do I think about registering the correct ComponentUi for different forms and think? Is this possible at all? If not, what is the most preferred way of writing a custom component to look different?


To be a bit more specific, at this time I am overriding the JComponent # updateUI different ComponentUi example to set my In custom component:

  @Override Public Zero Update (UI) (LookIFeel Feel = UIManager.getLookAndFeel (); If (for example WindowsLookAndFeel looks) {setUI (MyWindowsCustomUi.createUI (this)); } And if (for example MotifLookAndFeel) {setUI (MyMotivCustomUi.createUI (this)); } And if (for example MetalLookAndFeel) {setUI (MyMetalCustomUi.createUI (this)); } Other {setUI (MyBasicCustomUi.createUI (this)); }}   

But this approach completely defeats the utility of purpose and utilization altogether. I want to be able to convert it to:

  Public Zero Update (UI) (setUI (MyCustomUi) UIManager.getUI (this)); }   

And to see and feel it at the right time, set the correct sub class of MyCustomUi

I know, That I can easily get it by creating custom subclasses of each supported LookAndFeel , which register related ComponentUi during that time BasicLookAndFeel #initComponentDefaults (UIDefaults) - but this is not what I want to do.

If you want it or not - to register your custom UI in some way with UINGER If you is , then you may know more about them; -)

T is needed, however, is a custom subclass of supported LAFs: You can manually register them (and you can update the registration once the LF is changed, so you can use the UINEG But a property is needed) in such a case will be informed.

A JCIFT and UI implementation with the "Custom UI" classified after the general conventions (basic custom UI, Windows Custom UI ...) Registration will be something like this:

  string prefix = UIManager.getLookAndFeel (). GetID (); UIManager.getLookAndFeelDefaults (). Put ("CustomUI", myUIPackage + "." + Prefix + custom UI);   

Note that custom UI requires static createUI which gives an example of UEE:

  public static component UI createdUI (JCMPNAP) [new Basic Custom UI Refund (); }   

and the component needs to publish its uiClassID, and set its UI:

  @Override public string getUIClassID () {"CustomUI" Return; } @ Override Public Owned Update (UII) (Set UI (UINAZ.AR.JET) (this); }   

The advantage of using SwingX is to provide basic facilities to automatically register custom components. You'll need an additional class - customaddon - which provides per-lf configuration and contributes to the custom component in that edition: // contains JCustom static {LookAndFeelAddons.contribute ( New CustomAddon ()); } // CustomAddon @Override Secure Zero addBasicDefaults (LookAndFeelAddons addon, DefaultsList default) {super.addBasicDefaults (addon, defaults); Default.add ("CustomUI", "mypackage.BasicCustomUI"); } @ Override secured zero addMacDefaults (LookAndFeelAddons addon, DefaultsList default) {super.addMacDefaults (addon, defaults); Defaults.add ("CustomUI", "mypackage.MacCustomUI"); } // ... the same way for all supported LF

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -