The Artima Developer Community
Sponsored Link

Java Community News
Swing Styling With CSS

1 reply on 1 page. Most recent reply: Mar 28, 2006 11:57 PM by thomas hu

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Frank Sommers

Posts: 2642
Nickname: fsommers
Registered: Jan, 2002

Swing Styling With CSS Posted: Mar 27, 2006 10:09 AM
Reply to this message Reply
Summary
Swing is enjoying a renaissance, thanks in part to renewed interest in rich-client applications, and also because of new frameworks that aim to ease Swing development. One such framework, JAXX, lets you describe a Swing UI via XML, and even allows CSS stylesheets to define the appearance of Swing components.
Advertisement

Server-side Java sports numerous frameworks built on top of J2EE to help encapsulate common application concerns, making the development process more effective. Client-side Java frameworks started to emerge much slower: Only in the past two years did client-side frameworks finally start to simplify rich-client Java development.

One such framework, JAXX, allows you to specify a Swing UI in XML:

JAXX enables you to write simple XML files describing components and their interactions, and then compile those XML files into ordinary Java classes. User interface components can be developed much faster and more easily in JAXX than in ordinary Java code.
Among the more interesting aspects of JAXX is that it lets you specify the appearance of a Swing component vis CSS. A recent post by Ethan Nicholas describes how to do this. Given a UI component named Calculator, the following JAXX code can be specified:
<Application title='Calculator'>
  <style source='Calculator.css'/>
  <script source='Calculator.script'/>
</Application>
This XML snippet refers to a style sheet that JAXX will apply to the component:

Application {
    lookAndFeel: system;
}

#display {
    background: #BCE5AD;
    opaque: true;
    horizontalAlignment: right;
    border:    {BorderFactory.createBevelBorder(BevelBorder.LOWERED)};
    font-size: 22;
    font-weight: bold;
}

JButton {
    font-size: 18;
    width: 60;
    height: 35;
}

JButton.digit {
    foreground: blue;
}

The more usual Swing approach to changing a component's look-and-feel is to specify, well, a new look-and-feel for your application. Using CSS is a more direct approach, but I always had the sense that using XML to describe UIs creates GUIs that look generic, not to mention that introducing XML can make Swing development even more complex. However, JAXX's approach might still be useful, since CSS is so widely used.

What do you think of JAXX's approach to Swing styling?


thomas hu

Posts: 1
Nickname: tommycat
Registered: Mar, 2006

Re: Swing Styling With CSS Posted: Mar 28, 2006 11:57 PM
Reply to this message Reply
how about using SWT??
css is too complex for me

Flat View: This topic has 1 reply on 1 page
Topic: Swing Styling With CSS Previous Topic   Next Topic Topic: Register and Discover Services with ZeroConf's Java API


Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us