DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
  1. DZone
  2. Popular
  3. Open Source
  4. EaSynth Look And Feel Customization (1)

EaSynth Look And Feel Customization (1)

Xavier Young user avatar by
Xavier Young
·
Aug. 15, 08 · Interview
Like (0)
Save
Tweet
Share
11.64K Views

Join the DZone community and get the full member experience.

Join For Free

easynth look and feel is an extended synth look and feel from www.easynth.com , it is free and open-source under apache license 2.0, we can use it in our java application for free. but the default theme of easynth look and feel may not meet our requirements all the time, sometimes we may need to make some customization on easynth look and feel to obtain more suitable gui style.

as we already know, the synth look and feel does not provide a "default" theme, if we create an instance of javax.swing.plaf.synth.synthlookandfeel class (without loading any xml configuration file) and set it as the current look and feel in the uimanager, you will see an "empty" theme (shown in the following figure), which is not acceptable at all.

the empty theme of synth look and feel

so before we use synth look and feel in our products, we have to make proper configuration for all gui component styles in an xml file and load it into the look and feel object. there are 50+ gui components defined in swing, so creating a brand new look and feel from scratch is a little complex, but we can use easynth look and feel as a template and make customization on it, which also able to provide a brand new look and feel with less effort.

i will introduce the customization for different gui components on easynth look and feel in a serial of articles, this article is the first one, which will introduce the customization on regular button in easynth look and feel.

we can customize the synth based look and feel by changing its xml configuration file, painter class file and graphics utility class file. what's more, easynth look and feel provides some open properties, which allow us to custom the behavior of its painter and graphics utility.

easynth look and feel is built with a commercial ide product "easynth look and feel designer", the project file "easynthlookandfeel.lfp" is also enclosed in the open source bundle. if you have the license, you can use that ide to perform the customization, which will be a much easier job. but in these articles, i will focus on the way that performing customization without ide tool.

regular button customization

the following figure shows the four basic states of the regular button:

the button style for different states

first we can change the background images of the button, they are specified in "easynth.xml" file, which is enclosed in the "com/easynth/lookandfeel" folder inside "easynthlookandfeel.jar" file. now let's open the "easynth.xml" file and locate the "style" node with id "button", we will see the following:

<state value=" enabled ">
<imagepainter method="buttonbackground" path="resource/1204727000093_button_enabled.png" sourceinsets="5 5 5 5" paintcenter="true" stretch="true" center="false"/>
</state>
<state value=" mouse_over ">
<imagepainter method="buttonbackground" path="resource/1204727022828_button_mouseover.png" sourceinsets="5 5 5 5" paintcenter="true" stretch="true" center="false"/>
</state>
<state value=" pressed ">
<imagepainter method="buttonbackground" path="resource/1204727039640_button_pressed.png" sourceinsets="5 5 5 5" paintcenter="true" stretch="true" center="false"/>
</state>
<state value=" disabled ">
<imagepainter method="buttonbackground" path="resource/1204727048156_button_disabled.png" sourceinsets="5 5 5 5" paintcenter="true" stretch="true" center="false"/>
</state>

for each state, an imagepainter element is defined, the "method" attribute is set to "buttonbackground", means the imagepainter element is used to specify the background image for regular button. the "path" attribute present the location of the background image file. so the customization will be easy, we can just put some new images file into the "com\easynth\lookandfeel\resource" folder inside "easynthlookandfeel.jar" file and then change the path attributes for imagepainter elements in the xml.

here are my new background images for regular button:

new background images

i put them into the jar file and then modify the xml as follow:

<state value="enabled">
<imagepainter method="buttonbackground" path=" resource/new_button_enabled.png " sourceinsets="5 5 5 5" paintcenter="true" stretch="true" center="false"/>
</state>
<state value="mouse_over">
<imagepainter method="buttonbackground" path=" resource/new_button_mouseover.png " sourceinsets="5 5 5 5" paintcenter="true" stretch="true" center="false"/>
</state>
<state value="pressed">
<imagepainter method="buttonbackground" path=" resource/new_button_pressed.png " sourceinsets="5 5 5 5" paintcenter="true" stretch="true" center="false"/>
</state>
<state value="disabled">
<imagepainter method="buttonbackground" path=" resource/new_button_disabled.png " sourceinsets="5 5 5 5" paintcenter="true" stretch="true" center="false"/>
</state>

after update this xml to the jar file, and applay the new look and feel jar file in an example java project, we can see the effect:

new background effect

you will notice that the border of the button is not changed yet, but sometimes we need to change it as well. there are two open properties defined in easynth look and feel to define the dimension of the arc used in the border round corner:

  • easynth.button.arc.width: the width of the ellipse that the arc comes from.
  • easynth.button.arc.height: the height of the ellipse that the arc comes from.

the figure below shows that details for these two open properties:

the arc in the border of button

we can change the values of these properties in the xml, but keep in mind that the round corner of border should be consist with that of the background image:

<defaultsproperty key=" easynth.button.arc.width " type="integer" value="9"/>
<defaultsproperty key=" easynth.button.arc.height " type="integer" value="9"/>

we can also specify the border color for all states, there are another set of open properties defined to custom the border color, listed below:

<defaultsproperty key="easynth.button.border.color.enabled" type="idref" value=" button_border_color_enabled "/>
<defaultsproperty key="easynth.button.border.color.mouseover" type="idref" value=" button_border_color_mouseover "/>
<defaultsproperty key="easynth.button.border.color.pressed" type="idref" value=" button_border_color_pressed "/>
<defaultsproperty key="easynth.button.border.color.disabled" type="idref" value=" button_border_color_disabled "/>
<defaultsproperty key="easynth.button.border.color.default.enabled" type="idref" value=" button_border_color_default_enabled "/>
<defaultsproperty key="easynth.button.border.color.default.mouseover" type="idref" value=" button_border_color_default_mouseover "/>
<defaultsproperty key="easynth.button.border.color.default.pressed" type="idref" value=" button_border_color_default_pressed "/>
<defaultsproperty key="easynth.button.border.color.default.disabled" type="idref" value=" button_border_color_default_disabled "/>

the "type" attributes of these properties are set to "idref" means the value is linked to another object, and the id of that object is present in the "value" attribute. let's search the id "button_border_color_enabled" in the xml and we will see this:

<object id=" button_border_color_enabled " class="java.awt.color">
<int>192</int>
<int>170</int>
<int>145</int>
<int>255</int>
</object>

actually it is a java bean object that persisted with xml format, the four integer parameter are red, green, blue and alpha value of the color, which can be 0~255. we can modify this color object to change the border color for "enabled" state, we can also change other color objects to custom the border color for other states as well. the figure below shows the effect of my modification:

new button border color

we can also change the "insets" element under the button style, this element can specify the margin of the button text:

<insets top="4" left="6" bottom="4" right="6"/>

by specifying different value for "top", "left", "bottom" and "right", we can place the button text on different position, just like these:

button text positions

it is true that we can replace the "com.easynth.designer.laf.painter.easynthpainter" painter class used by easynth look and feel, to obtain the full flexibility to paint anything we need on the button, but this topic is out of the scope of this article. you can use the reference resource as the entrance to know more about that.

reference resource

easynth look and feel homepage: http://www.easynth.com/freewares/easynthlookandfeel.html

synth look and feel introduction from sun: http://java.sun.com/docs/books/tutorial/uiswing/lookandfeel/synth.html

synth look and feel wiki: http://en.wikipedia.org/wiki/synth_look_and_feel

synth look and feel javadoc: http://java.sun.com/javase/6/docs/api/javax/swing/plaf/synth/package-summary.html

synth xml file format: http://java.sun.com/javase/6/docs/api/javax/swing/plaf/synth/doc-files/synthfileformat.html

synth component specific properties: http://java.sun.com/javase/6/docs/api/javax/swing/plaf/synth/doc-files/componentproperties.html

synth painter javadoc: http://java.sun.com/javase/6/docs/api/javax/swing/plaf/synth/doc-http://java.sun.com/javase/6/docs/api/javax/swing/plaf/synth/synthpainter.html

Open source

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How To Build a Spring Boot GraalVM Image
  • Best CI/CD Tools for DevOps: A Review of the Top 10
  • Use Golang for Data Processing With Amazon Kinesis and AWS Lambda
  • [DZone Survey] Share Your Expertise and Take our 2023 Web, Mobile, and Low-Code Apps Survey

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: