The Source for Java Technology Collaboration
User: Password:



Start New Message Delete Post a Reply

Article: 
 Swing and CSS
Subject:  Using scripts?
Date:  2003-10-15 00:40:24
From:  velhonoja


Interesting article

What if we use script language like BeanShell (http://www.beanshell.org) to set up styles?
It gives more flexibility, though it makes XML file little more complex.

For example...

<beanshell>
gray = new Color( 250,250,250 );
green = new Color( 150,250,150 );

/*
method for setting borders
*/
handleBorder( obj, margin ){
m_border = BorderFactory.createEmptyBorder(margin,margin,margin,margin);
c_border = BorderFactory.createCompoundBorder(comp.getBorder(),m_border);
obj.setBorder(c_border);
}

/*
put all properties for JButton in one method
*/
handleJButton( button ){
button.setBackground( gray );
handleBorder( button, 3 );
button.setForeground( green );
}

</beanshell>
<rules>
<!--
current is Swing component which is being edited
-->
<rule class="JPanel"
beanshell="current.setBackground( green );"/>
<rule class="JTextField"
beanshell="handleBorder( current, 5 );"/>
<rule class="JButton"
beanshell="handleJButton( current );"/>
</rules>

 Feed java.net RSS Feeds