Java uses Synth to customize skin

Source: Internet
Author: User

1. Create a new project named untitled1

2. Create an application (file-> New-> Application)

3. Add a button in frame1.

4. Under the classes/untitled1directory, upload the Upload File (+down.gif={off.gif={on.gif, indicating the three statuses of the buttons respectively) and the demo. xml file.

The content in demo. XML is:

<Synth>

<Style id = "button">

<State>

<Imagepainter method = "buttonbackground" Path = "images/onon.gif"

Sourceinsets = "9 10 9 12" paintcenter = "true" stretch = "true"/>

<Insets Top = "9" Left = "10" Bottom = "9" Right = "12"/>

<Font name = "Aharoni" size = "16"/>

<Color type = "text_foreground" value = "# ffffff"/>

</State>

<State value = "mouse_over">

<Imagepainter method = "buttonbackground" Path = "images/1_down.gif"

Sourceinsets = "9 10 9 12" paintcenter = "true" stretch = "true"/>

<Insets Top = "9" Left = "10" Bottom = "9" Right = "12"/>

<Color type = "text_foreground" value = "# ffffff"/>

</State>

<State value = "pressed">

<Imagepainter method = "buttonbackground" Path = "images/1_off.gif"

Sourceinsets = "10 12 8 9" paintcenter = "true" stretch = "true"/>

<Insets Top = "10" Left = "12" Bottom = "8" Right = "9"/>

<Color type = "text_foreground" value = "# ffffff"/>

</State>

<Property key = "button. Margin" type = "insets" value = "0 0 0"/>

</Style>

<Bind style = "button" type = "region" Key = "button"/>

</Synth>

5. Add the following statement to the header of the application1.java file:

Import javax. Swing. plaf. synth. synthlookandfeel;

6. Modify the public void run () function as follows:

Public void run (){

Try {

// Add the following three statements

Synthlookandfeel synth = new synthlookandfeel ();

Synth. Load (application1.class. getresourceasstream ("demo. xml"), application1.class );

Uimanager. setlookandfeel (Synth );

/* Original statement

Uimanager. setlookandfeel (uimanager. getsystemlookandfeelclassname ());

*/

}

7. Compile and run the command to view the result.

8. The usage of other controls is similar.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.