Lwuit Custom Flexible Style component

Source: Internet
Author: User

When you use lwuit these component, if the layout of a page is more complex, a lot of components, and the page more, commonly used components such as Label,button,textfield,textarea will be used very ordinary. When using these components, we often set its style,style much like the Web CSS, which allows us to customize the border,font,fgcolor,bgcolor,margin,padding, and set the code for a component's style to be simple:

Code

This.getstyle (). SetBorder (Border Border)

But most of the components have style and selectedstyle, the button that can be clicked and its subclasses, and Pressedstyle, for example, which can only set the border when the component is unchecked, when it is selected It goes back to the way it was set in the system code. A page has many components, most of which have to set style (checked and unchecked style), although the code is simple, but when a page is written down, you'll find that at least half of your code is spent on layout and styling, and the code looks bloated.

Fortunately Lwuit is open source, we can modify its source code from the definition of these UI methods, find the Component.java file, we just need to add a few methods in this file to simplify our style settings.

Here are some of the methods I added in the Component.java class, code I write more rough, you can write your own way, theoretically each method should have two parameters, unchecked and selected state, the parameter can be null, need to make some judgments to fit the majority of the situation.

Code

//1469 line is added code
/**
* Set Custom font
* @param font
*/
public void SetC          Ustomfont (font font) {
This.getstyle (). SetFont (font);
This.getselectedstyle (). SetFont (font);
}
/**
* Set Horizontal direction margin
* @param margin
*/
public void Setcustomhor          Izontalmargin (int margin) {
This.getstyle (). SetMargin (Component.left, margin);
This.getstyle (). SetMargin (component.right, margin);
This.getselectedstyle (). SetMargin (Component.left, margin);
This.getselectedstyle (). SetMargin (component.right, margin);
}
/**
* Set custom border
* @param border
*/
public void Setcustombor          Der (Border Border) {
This.getstyle (). SetBorder (Border);
This.getselectedstyle (). SetBorder (border);   
}
/**
* Set Custom fgcolor
* @param unsectedcolor
    * Color when unchecked
* @param selectedcolor
* Color When selected
*/
Public V          OID Setcustomfgcolor (int unsectedcolor, int selectedcolor) {
This.getstyle (). Setfgcolor (Unsectedcolor);
This.getselectedstyle (). Setfgcolor (Selectedcolor);
}
/**
* Set Custom style
* Style contains checked and unchecked conditions, properties contain Margin,padding,border,fgco Lor,bgcolor,font
* @param unselectedstyle
* @param selectedstyle
*/
public void SE          Tcustomstyle (style unselectedstyle, style selectedstyle) {
This.setstyle (unselectedstyle);
This.setselectedstyle (Selectedstyle);
}

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.