Change the checkbox style in codename one - java

I couldn't manage it to customize the style of a checkbox component. The image for the selected state doesn't get shown when the application runs. I already set the border types to "Empty" for each relevant state. Did I miss something?
example image for the selected state
checkbox component in gui builder

First off you should look at the OnOffSwitch component and check it out in the component gallery as it looks exactly like what you are trying to accomplish.
You are customizing the components background not its state image. The state image is a special case image in the case of a check box that can be customized via theme constants and changes based on selected state. The background is unaware of those states, selected in this case is a synonym for focused...

Related

Change JComboBox colourms how?

I would like to change the color of the selected combobox.
I do not know name of this event.
It is not a background or foreground, so what then?
More on Image:
A renderer works for the items in the dropdown.
The same renderer is also used to render the value displayed in the combo box when the index value is -1. However, the background color is controlled by the UI so you can't just override it. That is the
UIManager.getColor("ComboBox.selectionBackground");
property is used to control the background so you have a consistent LAF that indicates when the combo box has focus. I don't know of any easy way to control this behaviour. You would need to write a custom UI that sets the background based on the selected value.
You would have to write a new renderer for the combo box. There are some good examples here: http://www.java2s.com/Code/Java/Swing-JFC/AfancyexampleofJComboBoxwithacustomrendererandeditor.htm
Specifically you will be writing a new Cell Renderer. There's a good tutorial for that here: http://www.java2s.com/Tutorial/Java/0240__Swing/Comboboxcellrenderer.htm
I hope that helps.
Greg

LWUIT in J2ME: setting the style of a list cell when pressed

I have a LWUIT J2ME app with a List. I would like for the background of a cell to change when it is clicked.
The first thing I had to do was set the background transparency and color of the whole list when it is selected. Otherwise, the background of the form behind it shows through when the list is clicked. I did that with this code:
catList.getSelectedStyle().setBgTransparency(255);
catList.getSelectedStyle().setBgColor(0x23222a);
This seems to work fine. When clicked, the list bg remains the same color.
Now I want the background of the clicked cell to change color when it is pressed. I tried this (cellCon is a Container):
cellCon.getPressedStyle().setBgTransparency(255);
cellCon.getPressedStyle().setBgColor(0xFFFFFF);
cellCon.getSelectedStyle().setBgTransparency(255);
cellCon.getSelectedStyle().setBgColor(0xFFFFFF);
But it has no effect. How can I get the effect that I want?
Thanks!
You have to get the listCellRender component to set the style of the pressed cell. I think that you can do that trying list.getRender and after that, set the Style.
If you are building a custom Render, take a look on this LWUIT Blog ListCellRender There is a method called getListFocusComponent, there you can return a component (like a label) whit the custom style that you want for your focus.

How to get the Button's icon coresponding to the current state it is in?

I want to extend the JButton class and manually paint the button's icon, though I need to get the correct icon according to the state the button is in, how do i do that?
Method getIcon() returns the default icon only, regardless of what state the button is in...
Instead, implement the Icon interface. ColorIcon, illustrated here, is a simple example used by a JButton subclass. Try instantiating ColorIcon for each of several colors . Use the Icon instances as the the button's pressed or rollover icon to see the effect. See also this related example.
getIcon() will return the default icon, but getDisabledIcon() will return the disabled icon.
Also
getDisabledSelectedIcon() returns the icon used by the button when it's disabled and selected. If no disabled selection icon has been set, this will forward the call to the LookAndFeel to construct an appropriate disabled Icon from the selection icon if it has been set and to getDisabledIcon() otherwise.
Some look and feels might not render the disabled selected Icon, in which case they will ignore this.
Then there is getPressedIcon(), getRollOverIcon() and getRolloverSelecedIcon().
Check the AbstractButton manual page.
As you can see there are many options available to you. On the other hand, you probably are the one who has set the icons, so if you may keep them in an Icon array, you could get them straight from there.

android change default color of selector and tab underline

How to change (using theme modifications) the default color of selector (ListView, GridView) and Tab selector/underline color.
I use actionbarsherlock and Theme.Sherlock as main application theme.
Below are the pictures describing what do I want to change.
Thanks
Unfortunately, if you want to style your action bar you will need to style its parts individually - there is no color attribute that would change the light blue color to something else.
Basically what you need to do is override styles and change some of the attributes and add some new drawables. If your action bar includes spinners, dropdown panels, radio buttons etc. you'll also need to provide new colored images for those. I recommend that you check the ActionBarSherlock styled sample (which you downloaded with the library), particularly its styles.xml.

Java SWT - Set ForeGround/Background Color of CTabItem (of CTabFolder)

I'm using a CTabFolder with several CTabItems. I would like to be able to set the background and foreground color of only a single CTabItem's tab.
There is an option for me to set the Font, but I can't find anything for the color or background of just the TabItem itself. Can anyone help?
Similar question was already addressed in How to correctly style borders of a CTabItem.
It's possible to set foreground (font) color and background (tabitem itself) color/gradient for selected and not selected (others) tabitems, see CTabFolder javadoc.
To do it just for one custom tabitem, you'll have to write your own CTabFolderRenderer, but it's really heavyweight solution.

Categories