[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 352
  • Last Modified:

Wrapping Swing Components

Hi, I want to create wrapper classes for most of the Swing GUI Components such as JButton, JTextField etc etc.
I want to keep this very simple but how do I go about doing this properly?

For example in the case of JButton, I will want a wrapper class MyJButton which will have colours and sizes specified by my wrapper class. So when I want a button I create a myJButton which will have a specific look and feel.

How do you properly wrap these classes. Would you simply subclass for example
public class MyJButton extends JButton
and then just set up the various attributes ?

Or alternatively does anyone know of any Look and Feel coding guidelines ?
I want to ensure that everyone when using the Swing components are forced to adhere to the same look and feel.

Thanks for your help
Regards Dave


 
0
RightSoBosco
Asked:
RightSoBosco
  • 6
  • 3
  • 2
  • +2
3 Solutions
 
zzynxSoftware engineerCommented:
>> Or alternatively does anyone know of any Look and Feel coding guidelines ?
Java Look and Feel Design Guidelines, Second Edition: http://java.sun.com/products/jlf/ed2/guidelines.html
0
 
CEHJCommented:
Some links on custom components here:

http://www.swtech.com/java/guidev/guicomp/
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
zzynxSoftware engineerCommented:
You can of course always have a look to how others did it:
e.g.  http://liquidlnf.sourceforge.net/
0
 
limaidealCommented:
jgoodies.com already have lots of freel, mature look and feels
0
 
objectsCommented:
Instead of creating a wrapper for each a better way would be to use the UIManager class to specify the default properties of the various component types
0
 
RightSoBoscoAuthor Commented:
Thanks for all the links :)

objects
When you say I should use the UIManager class to specify all the default properties.
Would this be similiar to the way the way it was done with this:
http://liquidlnf.sourceforge.net/
or is the liquidinf way too over the top ?




0
 
zzynxSoftware engineerCommented:
>> use the UIManager class to specify all the default properties
E.g. adapt the font of all JLabel's:

   UIManager.put("Label.font",new Font("Serif",Font.ITALIC,12));

All UI defaults can be found at http://www.rgagnon.com/javadetails/JavaUIDefaults.txt
0
 
zzynxSoftware engineerCommented:
If you want to generate the UI Defaults file yourself: http://www.rgagnon.com/javadetails/java-0507.html
0
 
objectsCommented:
> Would this be similiar to the way the way it was done with this:
http://liquidlnf.sourceforge.net/
> or is the liquidinf way too over the top ?

Typically you can use UIManager to modify the properties used by any look and feel.
Using a different l&f completely changes the entire look of an application, not just certain attributes.
If you only want to change things like colours and fonts then use UIManager.

eg. to change default panel background colour to red you'd use:

UIManager.put("Panel.background", Color.red);

No need to change the L&F to achieve this sort of thing.
0
 
RightSoBoscoAuthor Commented:
Thanks for the all the links and help there.
I split the points amonts three different parts which helped me out  the most.
Thanks again :-)
 
0
 
zzynxSoftware engineerCommented:
Thanks
0
 
objectsCommented:
:)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 6
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now